Commit d69df621 authored by robertDouglass's avatar robertDouglass
Browse files

Adding node.patch. This caches built nodes for authenticated users who only...

Adding node.patch. This caches built nodes for authenticated users who only have one role (authenticated user), aka your normal logged-in site user. Anonymously loaded nodes aren't cached because the page cache handles these, and nodes for users with more roles aren't cached because of the risk that they might render differently. In fact, there is some doubt that caching any built nodes is a viable solution. In any case, this reduces the queries to serve a Page to a logged in user from 24 to 19.
parent 74c35a0c
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.774
diff -u -r1.774 node.module
--- modules/node/node.module 11 Jan 2007 08:51:31 -0000 1.774
+++ modules/node/node.module 12 Jan 2007 22:59:32 -0000
@@ -484,17 +484,28 @@
* A fully-populated node object.
*/
function node_load($param = array(), $revision = NULL, $reset = NULL) {
+ global $user;
static $nodes = array();
if ($reset) {
+ foreach ($nodes as $node) {
+ dmemcache_delete($node->nid, 'node');
+ }
$nodes = array();
}
$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])) {
+ return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
+ }
+ $cached_node = dmemcache_get($param, 'node');
+ if ($cached_node && $cached_node->nid) {
+ $nodes[$param] = is_object($cached_node) ? drupal_clone($cached_node) : $cached_node;
+ return $nodes[$param];
+ }
}
$cond = 'n.nid = %d';
$arguments[] = $param;
@@ -532,8 +543,12 @@
$node->$key = $value;
}
}
+
if ($cachable) {
$nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
+ if (is_numeric($param) && count($user->roles) === 1 && in_array('authenticated user', $user->roles)) {
+ dmemcache_set($param, $nodes[$node->nid], 0, 'node');
+ }
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment