Index: xmlsitemap.generate.inc
===================================================================
--- xmlsitemap.generate.inc	(wersja 9420)
+++ xmlsitemap.generate.inc	(kopia robocza)
@@ -301,7 +301,7 @@
  */
 function xmlsitemap_regenerate_batch(array $smids = array()) {
   if (empty($smids)) {
-    $smids = xmlsitemap_db_fetch_col(db_query("SELECT smid FROM {xmlsitemap_sitemap}"));
+    $smids = xmlsitemap_db_fetch_col(db_query("SELECT smid FROM {xmlsitemap_sitemap} WHERE queued = 0"));
   }
 
   //$t = get_t();
@@ -320,18 +320,29 @@
   // @todo Get rid of this batch operation.
   $batch['operations'][] = array('_xmlsitemap_regenerate_before', array());
 
+  $queue = drupal_queue_get('xmlsitemap_regenerate_sitemap');
   // Generate all the sitemap pages for each context.
   foreach ($smids as $smid) {
-    $batch['operations'][] = array('xmlsitemap_regenerate_batch_generate', array($smid));
-    $batch['operations'][] = array('xmlsitemap_regenerate_batch_generate_index', array($smid));
+    // Enqueue all sitemaps for regeneration.
+    // Unprogressive batch isn't memory effictive enough.
+    $queue->createItem($smid);
   }
 
+
+  db_query(
+    "UPDATE {xmlsitemap_sitemap} SET queued = 1
+     WHERE smid IN (" . db_placeholders($smids, 'text') . ")",
+    $smids
+  );
+
+
   // Clear the regeneration flag.
   $batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_regenerate_needed' => FALSE)));
 
   return $batch;
 }
 
+
 /**
  * Batch callback; generate all pages of a sitemap.
  */
Index: xmlsitemap.module
===================================================================
--- xmlsitemap.module	(wersja 9420)
+++ xmlsitemap.module	(kopia robocza)
@@ -1631,6 +1631,7 @@
   return array($id, NULL, $bundle);
 }
 
+
 /**
  * Backport of the DBTNG fetchCol() from Drupal 7.
  */
@@ -1678,3 +1679,41 @@
   // Modify the hash so it's safe to use in URLs.
   return strtr($hash, array('+' => '-', '/' => '_', '=' => ''));
 }
+
+
+/**
+ * Implementation of hook_cron_queue_info().
+ *
+ * Invoked by drupal_queue module if present.
+ * xmlsitemap_regenerate_sitemap queue is used to store information
+ * about sitemaps enqueued for regeneration.
+ */
+function xmlsitemap_cron_queue_info() {
+  $queues = array();
+  $queues['xmlsitemap_regenerate_sitemap'] = array(
+    'worker callback' => 'xmlsitemap_sitemap_queue_worker',
+    'time' => variable_get('xmlsitemap_worker_time', 200),
+  );
+
+  return $queues;
+}
+
+
+/**
+ * Jobs queue worker. It regenerates sitemap for single sitemap.
+ * It reuses code from old, unprogressive batch implementation.
+ * It does the same like old version, but in single queue element we
+ * regenerate only one sitemap.
+ *
+ * @param string $smid
+ *   Sitemap id. This sitemap will be regenerated.
+ *
+ * @return void
+ *   This function only changes state.
+ */
+function xmlsitemap_sitemap_queue_worker($smid) {
+  module_load_include('generate.inc', 'xmlsitemap');
+  xmlsitemap_regenerate_batch_generate($smid);
+  xmlsitemap_regenerate_batch_generate_index($smid);
+  db_query("UPDATE {xmlsitemap_sitemap} SET queued = 0 WHERE smid = '%s'", $smid);
+}
Index: xmlsitemap.install
===================================================================
--- xmlsitemap.install	(wersja 9420)
+++ xmlsitemap.install	(kopia robocza)
@@ -278,13 +278,13 @@
         'not null' => TRUE,
         'default' => 0,
       ),
-      //'queued' => array(
-      //  'type' => 'int',
-      //  'unsigned' => TRUE,
-      //  'not null' => TRUE,
-      //  'default' => 0,
-      //  'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.',
-      //),
+      'queued' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.',
+      ),
     ),
     'primary key' => array('smid'),
   );
@@ -694,6 +694,30 @@
   return $ret;
 }
 
+
+/**
+ * Implements of hook_update_N().
+ *
+ * Add queued column at xmlsitemap_sitemap table.
+ */
+function xmlsitemap_update_6205() {
+  $ret = array();
+  db_add_field(
+    $ret,
+    'xmlsitemap_sitemap',
+    'queued',
+    array(
+      'type' => 'int',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0,
+      'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.',
+    )
+  );
+
+  return $ret;
+}
+
 function _xmlsitemap_sitemap_rehash_all() {
   // Reload the schema cache and reprocess all sitemap hashes into smids.
   drupal_load('module', 'xmlsitemap');
