### Eclipse Workspace Patch 1.0
#P Test Drupal 6 - NODE_CACHE
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.573
diff -u -r1.573 comment.module
--- modules/comment/comment.module	12 Aug 2007 16:12:00 -0000	1.573
+++ modules/comment/comment.module	23 Aug 2007 20:03:14 -0000
@@ -733,8 +733,6 @@
         // Update the comment in the database.
         db_query("UPDATE {comments} SET status = %d, timestamp = %d, subject = '%s', comment = '%s', format = %d, uid = %d, name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['status'], $edit['timestamp'], $edit['subject'], $edit['comment'], $edit['format'], $edit['uid'], $edit['name'], $edit['mail'], $edit['homepage'], $edit['cid']);
 
-        _comment_update_node_statistics($edit['nid']);
-
         // Allow modules to respond to the updating of a comment.
         comment_invoke_comment($edit, 'update');
 
@@ -799,14 +797,13 @@
         db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, thread, name, mail, homepage) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], ip_address(), $edit['timestamp'], $status, $thread, $edit['name'], $edit['mail'], $edit['homepage']);
         $edit['cid'] = db_last_insert_id('comments', 'cid');
 
-        _comment_update_node_statistics($edit['nid']);
-
         // Tell the other modules a new comment has been submitted.
         comment_invoke_comment($edit, 'insert');
 
         // Add an entry to the watchdog log.
         watchdog('content', 'Comment: added %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('fragment' => 'comment-'. $edit['cid'])));
       }
+      _comment_update_node_statistics($edit['nid']);
 
       // Clear the cache so an anonymous user can see his comment being added.
       cache_clear_all();
@@ -2035,6 +2032,7 @@
     $node = db_fetch_object(db_query("SELECT uid, created FROM {node} WHERE nid = %d", $nid));
     db_query("UPDATE {node_comment_statistics} SET comment_count = 0, last_comment_timestamp = %d, last_comment_name = '', last_comment_uid = %d WHERE nid = %d", $node->created, $node->uid, $nid);
   }
+  cache_clear_all($nid, 'cache_node');
 }
 
 /**
Index: modules/translation/translation.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/translation/translation.module,v
retrieving revision 1.8
diff -u -r1.8 translation.module
--- modules/translation/translation.module	12 Aug 2007 15:55:36 -0000	1.8
+++ modules/translation/translation.module	23 Aug 2007 20:03:19 -0000
@@ -296,6 +296,8 @@
         db_query('UPDATE {node} SET tnid = %d WHERE tnid = %d', $new_tnid, $node->tnid);
       }
     }
+    // TODO: finer grain deletion.
+    cache_clear_all('*', 'cache_node');
   }
 }
 
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.872
diff -u -r1.872 node.module
--- modules/node/node.module	20 Aug 2007 07:03:08 -0000	1.872
+++ modules/node/node.module	23 Aug 2007 20:03:15 -0000
@@ -450,6 +450,7 @@
  */
 function node_type_update_nodes($old_type, $type) {
   db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", $type, $old_type);
+  cache_clear_all('*', 'cache_node');
   return db_affected_rows();
 }
 
@@ -626,8 +627,17 @@
   $cachable = ($revision == NULL);
   $arguments = array();
   if (is_numeric($param)) {
-    if ($cachable && isset($nodes[$param])) {
-      return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
+    if ($cachable) {
+      if (!isset($nodes[$param])) {
+        if ($cache = cache_get($param, 'cache_node')) {
+          $nodes[$param] = $cache->data;
+        }
+      }
+      // Either the node was statically cached or we loaded form the
+      // cache_node table.
+      if (isset($nodes[$param])) {
+        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
+      }
     }
     $cond = 'n.nid = %d';
     $arguments[] = $param;
@@ -670,6 +680,7 @@
     }
     if ($cachable) {
       $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
+      cache_set($param, $nodes[$node->nid], 'cache_node');
     }
   }
 
@@ -866,6 +877,8 @@
 
   // Clear the page and block caches.
   cache_clear_all();
+  // Clear the node load cache for this node.
+  cache_clear_all($node->nid, 'cache_node');
 }
 
 /**
@@ -1196,6 +1209,7 @@
   if ($op == 'delete') {
     db_query('UPDATE {node} SET uid = 0 WHERE uid = %d', $user->uid);
     db_query('UPDATE {node_revisions} SET uid = 0 WHERE uid = %d', $user->uid);
+    cache_clear_all('*', 'cache_node');
   }
 }
 
Index: modules/node/node.schema
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.schema,v
retrieving revision 1.5
diff -u -r1.5 node.schema
--- modules/node/node.schema	10 Aug 2007 11:14:22 -0000	1.5
+++ modules/node/node.schema	23 Aug 2007 20:03:16 -0000
@@ -105,6 +105,7 @@
     'primary key' => array('type'),
   );
 
+  $schema['cache_node'] = drupal_get_schema_unprocessed('system', 'cache');
+
   return $schema;
 }
-
Index: modules/poll/poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v
retrieving revision 1.237
diff -u -r1.237 poll.module
--- modules/poll/poll.module	9 Aug 2007 10:37:41 -0000	1.237
+++ modules/poll/poll.module	23 Aug 2007 20:03:16 -0000
@@ -299,24 +299,6 @@
   while ($choice = db_fetch_array($result)) {
     $poll->choice[$choice['chorder']] = $choice;
   }
-
-  // Determine whether or not this user is allowed to vote
-  $poll->allowvotes = FALSE;
-  if (user_access('vote on polls') && $poll->active) {
-    if ($user->uid) {
-      $result = db_fetch_object(db_query('SELECT chorder FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid));
-    }
-    else {
-      $result = db_fetch_object(db_query("SELECT chorder FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, ip_address()));
-    }
-    if (isset($result->chorder)) {
-      $poll->vote = $result->chorder;
-    }
-    else {
-      $poll->vote = -1;
-      $poll->allowvotes = TRUE;
-    }
-  }
   return $poll;
 }
 
@@ -382,6 +364,25 @@
   global $user;
   $output = '';
 
+  // Determine whether or not this user is allowed to vote
+  $poll->allowvotes = FALSE;
+  if (user_access('vote on polls') && $poll->active) {
+    if ($user->uid) {
+      $result = db_fetch_object(db_query('SELECT chorder FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid));
+    }
+    else {
+      $result = db_fetch_object(db_query("SELECT chorder FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, ip_address()));
+    }
+    if (isset($result->chorder)) {
+      $poll->vote = $result->chorder;
+    }
+    else {
+      $poll->vote = -1;
+      $poll->allowvotes = TRUE;
+    }
+  }
+
+
   // Special display for side-block
   if ($block) {
     // No 'read more' link
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.138
diff -u -r1.138 system.install
--- modules/system/system.install	22 Aug 2007 08:40:04 -0000	1.138
+++ modules/system/system.install	23 Aug 2007 20:03:17 -0000
@@ -3527,6 +3527,30 @@
 }
 
 /**
+ * Add the node load cache table.
+ */
+function system_update_6028() {
+  $ret = array();
+
+  // Create the cache_node table.
+  $schema['cache_node'] = array(
+    'fields' => array(
+      'cid'        => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+      'data'       => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
+      'expire'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'created'    => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'headers'    => array('type' => 'text', 'not null' => FALSE),
+      'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
+    ),
+    'indexes' => array('expire' => array('expire')),
+    'primary key' => array('cid'),
+  );
+  db_create_table($ret, 'cache_node', $schema['cache_node']);
+
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
  */
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.522
diff -u -r1.522 system.module
--- modules/system/system.module	22 Aug 2007 08:36:34 -0000	1.522
+++ modules/system/system.module	23 Aug 2007 20:03:19 -0000
@@ -1868,6 +1868,7 @@
     node_types_rebuild();
     menu_rebuild();
     cache_clear_all('schema', 'cache');
+    cache_clear_all('*', 'cache_node');
     drupal_set_message(t('The configuration options have been saved.'));
   }
 
