If the ID is passed an array that does not work in the cache node_load().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

orb’s picture

Fix

diff --git a/modules/node/node.module b/modules/node/node.module
index 4cc6bdf..7907a4b 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -726,6 +726,9 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) {
     $arguments[] = $param;
   }
   elseif (is_array($param)) {
+    if ($cachable && count($param) == 1 && isset($param['nid']) && isset($nodes[$param['nid']])) {
+      return is_object($nodes[$param['nid']]) ? drupal_clone($nodes[$param['nid']]) : $nodes[$param['nid']];
+    }
     // Turn the conditions into a query.
     foreach ($param as $key => $value) {
       $cond[] = 'n.'. db_escape_table($key) ." = '%s'";
timmillwood’s picture

Status: Active » Needs review

How about you don't passing the nid as an array? Then it will be cached?

Status: Needs review » Needs work

The last submitted patch, node-cache in node_load-1765756-1.patch, failed testing.

orb’s picture

http://api.drupal.org/api/drupal/modules%21node%21node.module/function/n...

If nid not array

static $nodes = array();
  if (is_numeric($param)) {
      if (isset($nodes[$param])) {
        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
orb’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, node-cache in node_load-1765756-1.patch, failed testing.

podarok’s picture

try to remove whitespaces from patch filename

orb’s picture

orb’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, node-cache_in_node_load-1765756-8.patch, failed testing.

orb’s picture

Status: Needs work » Needs review
FileSize
671 bytes

next step )

podarok’s picture

Version: 6.26 » 6.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs reroll

#11 looks good for me, but possibly we need some test for it...
and reroll for 6.x-dev branch

podarok’s picture

Issue tags: -Needs tests

removed tag for Drupal 6
due to
http://drupal.org/node/1468170

Drupal version
Drupal 7.x, Drupal 8.x
orb’s picture

Status: Needs work » Needs review

Actual for 6.x-dev 2012-Sep-15

orb’s picture

FileSize
860 bytes

how-to check

  1. Install drupal 6
  2. Create 2 nodes
  3. Install module test_patch (in attach)
  4. open page node/1 => you see 2 warnings: "Call the function node_load(array('nid' => 2))."
  5. apply patch
  6. open page node/1 => you see 1 warning: "Call the function node_load(array('nid' => 2))."
podarok’s picture

tagging

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.