From 801756e7e69cfc8a22d8c1c612a31391872c35bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Sat, 25 Aug 2007 09:25:49 +0000 Subject: #111127 by chx: cache node_load(), so heavy operations loading data from external sources and only invoked once (note that you should do everything dynamic in the view op, not the load op) --- modules/node/node.module | 22 ++++++++++++++++++++-- modules/node/node.schema | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'modules/node') diff --git a/modules/node/node.module b/modules/node/node.module index ea156904a..9f21f1be3 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -450,6 +450,7 @@ function node_type_delete($type) { */ 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', TRUE); return db_affected_rows(); } @@ -626,8 +627,17 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) { $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 from 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,11 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) { } if ($cachable) { $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node; + // We can only cache when a nid is given, otherwise the conditions are + // too dynamic to be cacheable. + if (is_numeric($param)) { + cache_set($param, $nodes[$node->nid], 'cache_node'); + } } } @@ -866,6 +881,8 @@ function node_save(&$node) { // 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 +1213,7 @@ function node_user($op, &$edit, &$user) { 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', TRUE); } } diff --git a/modules/node/node.schema b/modules/node/node.schema index 30e70bf9c..76e942341 100644 --- a/modules/node/node.schema +++ b/modules/node/node.schema @@ -105,6 +105,7 @@ function node_schema() { 'primary key' => array('type'), ); + $schema['cache_node'] = drupal_get_schema_unprocessed('system', 'cache'); + return $schema; } - -- cgit v1.2.3