diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-11-17 22:14:43 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-11-17 22:14:43 +0000 |
commit | 38c91a8d9571a5978e84d0d122dd5bf1a54e1a2f (patch) | |
tree | b0d5d4e3ed44ff08a532140c83cf435d4bbf4201 /modules | |
parent | 4dafd85f54d45695a50d18152dda45cad1dfc397 (diff) | |
download | brdo-38c91a8d9571a5978e84d0d122dd5bf1a54e1a2f.tar.gz brdo-38c91a8d9571a5978e84d0d122dd5bf1a54e1a2f.tar.bz2 |
- Patch #8506 by Gerhard: added basic node_load() caching.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/node.module | 22 | ||||
-rw-r--r-- | modules/node/node.module | 22 |
2 files changed, 40 insertions, 4 deletions
diff --git a/modules/node.module b/modules/node.module index 75b6f4594..30fc7c4ab 100644 --- a/modules/node.module +++ b/modules/node.module @@ -365,11 +365,25 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { * will simply use array('nid' => 52). * @param $revision * Which numbered revision to load. Defaults to the current version. + * @param $reset + * Whether to reset the internal node_load cache. * * @return * A fully-populated node object. */ -function node_load($conditions, $revision = -1) { +function node_load($conditions, $revision = NULL, $reset = NULL) { + static $nodes = array(); + + if ($reset) { + $nodes = array(); + } + + $cachable = (count($conditions) == 1 && isset($conditions['nid']) && $revision == NULL); + + if ($cachable && isset($nodes[$conditions['nid']])) { + return $nodes[$conditions['nid']]; + } + // Turn the conditions into a query. foreach ($conditions as $key => $value) { $cond[] = 'n.'. check_query($key) ." = '". check_query($value) ."'"; @@ -399,10 +413,14 @@ function node_load($conditions, $revision = -1) { } // Return the desired revision. - if ($revision != -1 && is_array($node->revisions[$revision])) { + if (!is_null($revision) && is_array($node->revisions[$revision])) { $node = $node->revisions[$revision]['node']; } + if ($cachable) { + $nodes[$conditions['nid']] = $node; + } + return $node; } diff --git a/modules/node/node.module b/modules/node/node.module index 75b6f4594..30fc7c4ab 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -365,11 +365,25 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { * will simply use array('nid' => 52). * @param $revision * Which numbered revision to load. Defaults to the current version. + * @param $reset + * Whether to reset the internal node_load cache. * * @return * A fully-populated node object. */ -function node_load($conditions, $revision = -1) { +function node_load($conditions, $revision = NULL, $reset = NULL) { + static $nodes = array(); + + if ($reset) { + $nodes = array(); + } + + $cachable = (count($conditions) == 1 && isset($conditions['nid']) && $revision == NULL); + + if ($cachable && isset($nodes[$conditions['nid']])) { + return $nodes[$conditions['nid']]; + } + // Turn the conditions into a query. foreach ($conditions as $key => $value) { $cond[] = 'n.'. check_query($key) ." = '". check_query($value) ."'"; @@ -399,10 +413,14 @@ function node_load($conditions, $revision = -1) { } // Return the desired revision. - if ($revision != -1 && is_array($node->revisions[$revision])) { + if (!is_null($revision) && is_array($node->revisions[$revision])) { $node = $node->revisions[$revision]['node']; } + if ($cachable) { + $nodes[$conditions['nid']] = $node; + } + return $node; } |