<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Slow form submission - 26k+ draft posts - function improvement request</title>
		<link>https://legacy.forums.gravityhelp.com/topic/slow-form-submission-26k-draft-posts-function-improvement-request</link>
		<description>Gravity Support Forums Topic: Slow form submission - 26k+ draft posts - function improvement request</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 18:28:05 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/slow-form-submission-26k-draft-posts-function-improvement-request" rel="self" type="application/rss+xml" />

		<item>
			<title>Rob Harrell on "Slow form submission - 26k+ draft posts - function improvement request"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/slow-form-submission-26k-draft-posts-function-improvement-request#post-373087</link>
			<pubDate>Wed, 10 Jul 2013 08:23:46 +0000</pubDate>
			<dc:creator>Rob Harrell</dc:creator>
			<guid isPermaLink="false">373087@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Dev team has added this to Pivotal Tracker for discussion.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>MarketplaceHomes on "Slow form submission - 26k+ draft posts - function improvement request"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/slow-form-submission-26k-draft-posts-function-improvement-request#post-371700</link>
			<pubDate>Tue, 09 Jul 2013 17:25:31 +0000</pubDate>
			<dc:creator>MarketplaceHomes</dc:creator>
			<guid isPermaLink="false">371700@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks much!&#60;/p&#62;
&#60;p&#62;Gravity forms works very nicely, but the cycling through all current posts with 26k records was getting to be a showstopper as it was causing submissions to take almost 30 seconds.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Rob Harrell on "Slow form submission - 26k+ draft posts - function improvement request"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/slow-form-submission-26k-draft-posts-function-improvement-request#post-371553</link>
			<pubDate>Tue, 09 Jul 2013 15:41:37 +0000</pubDate>
			<dc:creator>Rob Harrell</dc:creator>
			<guid isPermaLink="false">371553@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'll bring this up to the dev team.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>MarketplaceHomes on "Slow form submission - 26k+ draft posts - function improvement request"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/slow-form-submission-26k-draft-posts-function-improvement-request#post-371549</link>
			<pubDate>Tue, 09 Jul 2013 15:40:43 +0000</pubDate>
			<dc:creator>MarketplaceHomes</dc:creator>
			<guid isPermaLink="false">371549@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Just a quick followup to note that I did what I recommended above to our copy of gravity forms and the result speaks for itself:&#60;/p&#62;
&#60;p&#62;26K draft posts ( from gravity forms ).&#60;/p&#62;
&#60;p&#62;Original processing time for form submissions: 26-28 seconds&#60;/p&#62;
&#60;p&#62;New processing time for form submissions: 2-3 seconds&#60;/p&#62;
&#60;p&#62;Here is the re-written code ( it could be done differently ) with my debug code and error handling taken out:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;private static function get_default_post_title(){

	global $wpdb;

	# A default to use for the final title to return
	$final_title = &#38;#39;Untitled_1&#38;#39;;

	# Grab the most recent post that has Untitled_*
	$sql = &#38;quot;SELECT ID, post_title FROM {$wpdb-&#38;gt;posts} WHERE post_title like &#38;#39;Untitled\_%&#38;#39; ORDER BY post_date DESC LIMIT 0, 1&#38;quot;;

	$results = $wpdb-&#38;gt;get_results( $sql, ARRAY_A );
	if ( !is_null($results) ) {
		# found a match
		if ( is_array($results) ) {
			if ( count($results) &#38;gt; 0 ) {
				$match = array_pop($results);
				$found_title = $match[&#38;#39;post_title&#38;#39;];
				$wanted_part = str_replace(&#38;#39;Untitled_&#38;#39;, &#38;#39;&#38;#39;, $found_title);
				$wanted_part = (int)$wanted_part;
				if ( $wanted_part &#38;gt; 0 ) {
					# we successfully found the wanted Untitled entry
					$wanted_part += 1;
				} else {
					# non numeric Untitled_* - start with the post ID + 1 when doing checks
					$wanted_part = (int)$match[&#38;#39;ID&#38;#39;] + 1;
				}
				# Update the default title
				$final_title = &#38;quot;Untitled_{$wanted_part}&#38;quot;;

				# Set up our early break flag
				$done_with_loop = false;

				# Check for existence of the wanted part ( up to 100 times )
				# - still much faster than looping 26k times
				for ( $i = 0; $i &#38;lt; 100; $i++ ) {
					$sql = &#38;quot;SELECT 1 as &#38;lt;code&#38;gt;it_exists&#38;lt;/code&#38;gt; FROM {$wpdb-&#38;gt;posts} WHERE post_title = &#38;#39;Untitled_{$wanted_part}&#38;#39;&#38;quot;;

					$exists = $wpdb-&#38;gt;get_results( $sql, ARRAY_A );
					if ( is_null($exists) ) {
						# no results returned
						if ( !empty( $wpdb-&#38;gt;last_error ) ) {
							# Error with query
						} else {
							# simply not found
							$final_title = &#38;quot;Untitled_{$wanted_part}&#38;quot;;
							$done_with_loop = true;
						}
					} else {
						if ( is_array($exists) &#38;amp;&#38;amp; count($exists) &#38;gt; 0 ) {
							$test = array_pop($exists);
							if ( &#38;#39;1&#38;#39; == &#38;quot;{$test[&#38;#39;it_exists&#38;#39;]}&#38;quot; ) {
								# this exists - try the next item
								$wanted_part += 1;
							} else {
								# does not exist - good to go
								$final_title = &#38;quot;Untitled_{$wanted_part}&#38;quot;;
								$done_with_loop = true;
							}
						} else {
							# no matches found
							$final_title = &#38;quot;Untitled_{$wanted_part}&#38;quot;;
							$done_with_loop = true;
						}
					}
					if ( $done_with_loop ) {
						break;
					}
				}
			} else {
				# no match found for Untitled_* in the system
				# - should not happen - treat as an error
			}
		} else {
			# not an array
			# - should not happen - treat as error
		}
	} else {
		# no results at all likely an error
		if ( !empty($wpdb-&#38;gt;last_error) ) {
			# database call error
		} else {
			# null result but no last error
		}
	}

	return $final_title;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Rewriting this function in the core code base would be greatly appreciated by those of us with much larger recordsets.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>MarketplaceHomes on "Slow form submission - 26k+ draft posts - function improvement request"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/slow-form-submission-26k-draft-posts-function-improvement-request#post-369370</link>
			<pubDate>Mon, 08 Jul 2013 21:37:21 +0000</pubDate>
			<dc:creator>MarketplaceHomes</dc:creator>
			<guid isPermaLink="false">369370@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;We are running quite a few Gravity Forms forms and form submissions have slowed down significantly over time.&#60;/p&#62;
&#60;p&#62;I wrote a timer utility to check and see which part of the process was taking so much extra time and was a bit surprised to see that the actual entry creation was taking 26+ seconds per form submission.&#60;/p&#62;
&#60;p&#62;After a bit of digging, I narrowed the culprit down ( gravity forms 1.7.6 ) to the forms_model.php file, get_default_post_title function.&#60;/p&#62;
&#60;p&#62;Currently it looks like the following:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;private static function get_default_post_title(){
        global $wpdb;
        $title = &#38;quot;Untitled&#38;quot;;
        $count = 1;

        $titles = $wpdb-&#38;gt;get_col(&#38;quot;SELECT post_title FROM $wpdb-&#38;gt;posts WHERE post_title like &#38;#39;%Untitled%&#38;#39;&#38;quot;);
        $titles = array_values($titles);
        while(in_array($title, $titles)){
            $title = &#38;quot;Untitled_$count&#38;quot;;
            $count++;
        }
        return $title;
    }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;With 25000 records that match, a procedural language approach ( like C, C++, php, etc. ) will take a good long while to run through the loop and find an untaken value.&#60;/p&#62;
&#60;p&#62;It would be much better to use a set language approach ( sql ) which might look like the following:&#60;/p&#62;
&#60;ol&#62;
&#60;li&#62;Grab the ID ( or title ) of the most recently added post&#60;/li&#62;
&#60;li&#62;Add one to the ID ( or parse the title, grab the integer, and increment it )&#60;/li&#62;
&#60;li&#62;Set the title to Untitled_N where N is the result of the integer found + 1&#60;/li&#62;
&#60;li&#62;If needed, use a small loop to check for existence of a post having that title, and increment the integer until an unused title is found&#60;/li&#62;
&#60;li&#62;return the resulting title&#60;/li&#62;
&#60;/ol&#62;
&#60;p&#62;Doing things this way would save a ton of processing power and time, and the fix would be rather simple.&#60;/p&#62;
&#60;p&#62;Obviously, it would be even better to use a custom post type for these things as that would avoid cluttering the post list with tons of drafts, allow full control over title generation ( e.g. with your own custom post type you could be certain the next unused id was available for use as a title ), etc. But that would also take a lot more work, especially to maintain backward compatibility.&#60;/p&#62;
&#60;p&#62;Anywise, if you could take a look at that function and revise it so that it doesn't bog larger systems down, it would be much appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
