Heine

  • drupal
  • drupal core commits
  • about
Home

Commit 214068 by webchick

#457080 by moshe weitzman: Add node_delete_multiple() for more efficient deletion of lots of nodes.

--- modules/node/node.admin.inc 2009/05/15 03:58:35     1.46
+++ modules/node/node.admin.inc 2009/05/20 05:39:45     1.47
@@ -620,7 +620,6 @@
 }
 
 function node_multiple_delete_confirm(&$form_state, $nodes) {
-
   $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
   // array_filter returns only elements with TRUE values
   foreach ($nodes as $nid => $value) {
@@ -645,13 +644,10 @@
 
 function node_multiple_delete_confirm_submit($form, &$form_state) {
   if ($form_state['values']['confirm']) {
-    foreach ($form_state['values']['nodes'] as $nid => $value) {
-      node_delete($nid);
-    }
-    $message = format_plural(count($form_state['values']['nodes']),
-                            'The item has been deleted.',
-                            'The items have been deleted.');
-    drupal_set_message($message);
+    node_delete_multiple(array_keys($form_state['values']['nodes']));
+    $count = count($form_state['values']['nodes']);
+    watchdog('content', 'Deleted @count posts.', array('@count' => $count));
+    drupal_set_message(t('Deleted @count posts.', array('@count' => $count)));
   }
   $form_state['redirect'] = 'admin/content/node';
   return;

--- modules/node/node.module    2009/05/18 14:25:53     1.1049
+++ modules/node/node.module    2009/05/20 05:39:45     1.1050
@@ -782,7 +782,8 @@
  *   An array of node objects indexed by nid.
  */
 function node_load_multiple($nids = array(), $conditions = array(), $reset = FALSE) {
-  static $node_cache = array();
+  $node_cache = &drupal_static(__FUNCTION__, array());
+
   if ($reset) {
     $node_cache = array();
   }
@@ -934,7 +935,7 @@
  * @param $vid
  *   The revision ID.
  * @param $reset
- *   Whether to reset the internal node_load cache.
+ *   Whether to reset the node_load_multiple cache.
  *
  * @return
  *   A fully-populated node object.
@@ -1154,39 +1155,50 @@
 
 /**
  * Delete a node.
+ *
+ * @param $nid
+ *   A node ID.
  */
 function node_delete($nid) {
+  node_delete_multiple(array($nid));
+}
 
-  $node = node_load($nid);
+/**
+ * Delete multiple nodes.
+ *
+ * @param $nids
+ *   An array of node IDs.
+ */
+function node_delete_multiple($nids) {
+  $nodes = node_load_multiple($nids, array());
 
-  if (node_access('delete', $node)) {
-    db_delete('node')
-      ->condition('nid', $node->nid)
-      ->execute();
-    db_delete('node_revision')
-      ->condition('nid', $node->nid)
-      ->execute();
-    db_delete('history')
-      ->condition('nid', $node->nid)
-      ->execute();
+  db_delete('node')
+    ->condition('nid', $nids, 'IN')
+    ->execute();
+  db_delete('node_revision')
+    ->condition('nid', $nids, 'IN')
+    ->execute();
+  db_delete('history')
+    ->condition('nid', $nids, 'IN')
+    ->execute();
 
+  foreach ($nodes as $nid => $node) {
     // Call the node-specific callback (if any):
     node_invoke($node, 'delete');
     module_invoke_all('node_delete', $node);
 
-    // Clear the page and block caches.
-    cache_clear_all();
-
     // Remove this node from the search index if needed.
     // This code is implemented in node module rather than in search module,
     // because node module is implementing search module's API, not the other
     // way around.
     if (module_exists('search')) {
-      search_wipe($node->nid, 'node');
+      search_wipe($nid, 'node');
     }
-    watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
-    drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title)));
   }
+
+  // Clear the page and block and node_load_multiple caches.
+  cache_clear_all();
+  drupal_static_reset('node_load_multiple');
 }
 
 /**

--- modules/node/node.pages.inc 2009/05/09 18:28:12     1.64
+++ modules/node/node.pages.inc 2009/05/20 05:39:45     1.65
@@ -521,7 +521,10 @@
  */
 function node_delete_confirm_submit($form, &$form_state) {
   if ($form_state['values']['confirm']) {
+    $node = node_load($form_state['values']['nid']);
     node_delete($form_state['values']['nid']);
+    watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
+    drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title)));
   }
 
   $form_state['redirect'] = '<front>';

No votes yet
  • Drupal Core
  • Download patch

Recent posts

  • Drupal 6: $base_path doesn't always point to the frontpage
  • XNA SoundEffect ContentLoadException
  • A new form element in Drupal core
  • The backstabbing March-Hare
  • Drupal HEAD and HTTP 500 errors on IIS 7

All-time popular content

  • Update UID 1 password via JS
  • Keeping an eye on Drupal core
  • Subversion on Strato V-PowerServer
  • A new form element in Drupal core
  • Access denied - Are you sure?
more

Tags

Captcha Coding Drupal FAPI IIS Let's hope it doesn't become popular Performance PHP Planet Drupal Quiz Security V-PowerServer
more tags
  • drupal
  • drupal core commits
  • about

Copyright © 2009 by Heine Deelstra. All rights reserved.