? boost-544476.patch
Index: boost.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.admin.inc,v
retrieving revision 1.1.2.1.2.3.2.47
diff -u -p -r1.1.2.1.2.3.2.47 boost.admin.inc
--- boost.admin.inc	6 Aug 2009 08:20:31 -0000	1.1.2.1.2.3.2.47
+++ boost.admin.inc	10 Aug 2009 05:15:18 -0000
@@ -358,11 +358,15 @@ function boost_admin_boost_performace_pa
       5 => t('5 Show all'),
     ),
   );
-  $form['advanced']['boost_stop_crawler'] = array(
-    '#type' => 'submit',
-    '#value' => t('Stop Crawler. !count out of !total URL\'s done.', array( '!count' => variable_get('boost_crawler_position', 0), '!total' => boost_crawler_total_count())),
-    '#submit' => array('boost_stop_crawler_submit'),
-  );
+  $total = boost_crawler_total_count();
+  $number_done = min($total, variable_get('boost_crawler_position', 0));
+  if (variable_get('boost_crawler_number_of_threads', 0) != 0 && $total != $number_done) {
+    $form['advanced']['boost_stop_crawler'] = array(
+      '#type' => 'submit',
+      '#value' => t('Stop Crawler. !count URL\'s left.', array('!count' => $total - $number_done)),
+      '#submit' => array('boost_stop_crawler_submit'),
+    );
+  }
 
   // Apache .htaccess settings generation
   $htaccess = boost_admin_generate_htaccess(variable_get('boost_server_name_http_host', '%{SERVER_NAME}'), variable_get('boost_document_root', '%{DOCUMENT_ROOT}'), 'cache', 'gz', variable_get('boost_file_extension', '.html'));
@@ -597,10 +601,6 @@ function boost_count_core_db($all = FALS
   return db_result(db_query("SELECT COUNT(*) FROM {cache_page}"));
 }
 
-function boost_crawler_total_count() {
-  return db_result(db_query("SELECT COUNT(*) FROM {boost_crawler}"));
-}
-
 /**
  * Flushes boost page cache
  */
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.90
diff -u -p -r1.3.2.2.2.5.2.90 boost.module
--- boost.module	6 Aug 2009 14:56:03 -0000	1.3.2.2.2.5.2.90
+++ boost.module	10 Aug 2009 05:15:19 -0000
@@ -1976,13 +1976,19 @@ function boost_crawler_init() {
         //Spin Up Threads
         $thread_primed = variable_get('boost_crawler_threads_primed', FALSE);
         $threads = 2;
+        $step = 25;
         if (!$thread_primed) {
           variable_set('boost_crawler_threads_primed', TRUE);
+          $total = boost_crawler_total_count() - $step;
+          if ($total/$step < $threads) {
+            $threads = floor($total/$step);
+          }
           while ($threads > 0) {
             $threads--;
             boost_async_call_crawler($self);
           }
           watchdog('boost', 'All threads started');
+          variable_set('boost_crawler_number_of_threads', $threads);
           exit;
         }
 
@@ -1992,16 +1998,21 @@ function boost_crawler_init() {
           exit;
         }
 
-        $step = 25;
-        // Wait 0 to 3 seconds before grabing DB position counter.
-        usleep(mt_rand(0,3000000));
+        // Wait 0 to 1 seconds before grabing DB position counter.
+        usleep(mt_rand(0,1000000));
+        db_lock_table('variable');
         $from = unserialize(db_result(db_query("SELECT value FROM {variable} WHERE name = 'boost_crawler_position'")));
         variable_set('boost_crawler_position', ($from + $step));
+        db_unlock_tables();
 
         $results = db_query_range("SELECT url FROM {boost_crawler} ORDER BY id ASC", $from, $step);
         $url = db_result($results);
         if (!$url) {
-          watchdog('boost', 'Crawler Done');
+          db_lock_table('variable');
+          $threads = variable_get('boost_crawler_number_of_threads', 0);
+          variable_set('boost_crawler_number_of_threads', ($threads-1));
+          db_unlock_tables();
+          watchdog('boost', 'Crawler Done. Thread %num.', array('%num' => $threads));
           return TRUE;
         }
         else {
@@ -2026,6 +2037,10 @@ function boost_crawler_init() {
       }
     }
   }
+  elseif (variable_get('boost_crawler_number_of_threads', 0) != 0) {
+    watchdog('boost', 'Crawler already running');
+    drupal_set_message(t('Boost: Craler is already running. Atempt to start crawler failed.'), 'warning');
+  }
   elseif (variable_get('cron_semaphore', FALSE) == TRUE) {
     // This function called from cron; reset & call self.
     watchdog('boost', 'Crawler Start');
@@ -2142,3 +2157,10 @@ function boost_crawler_init_tables() {
   }
   else {return FALSE;}
 }
+
+/**
+ * Get count of boost_crawler table.
+ */
+function boost_crawler_total_count() {
+  return db_result(db_query("SELECT COUNT(*) FROM {boost_crawler}"));
+}
