summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-08-25 09:25:49 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-08-25 09:25:49 +0000
commit801756e7e69cfc8a22d8c1c612a31391872c35bc (patch)
tree3d70f6ee8d720628bf87039193a4fac07a1e6613 /modules/node
parent92914245608123f9e011d1e9d4cf8c057bc9e8a8 (diff)
downloadbrdo-801756e7e69cfc8a22d8c1c612a31391872c35bc.tar.gz
brdo-801756e7e69cfc8a22d8c1c612a31391872c35bc.tar.bz2
#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)
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.module22
-rw-r--r--modules/node/node.schema3
2 files changed, 22 insertions, 3 deletions
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;
}
-