Commit 38c91a8d authored by Dries's avatar Dries

- Patch #8506 by Gerhard: added basic node_load() caching.
parent 4dafd85f
......@@ -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;
}
......
......@@ -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;
}
......
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