Hello All, Since I see so many node loads in block visibility and in modules that do $node manipulations and so forth, which would make me think that sometimes many node loads might occur on some pages and tens perhaps when you add contributed modules on that, I was wondering why not just load $node globally on node/<num>/* pages like we do with $user to avoid any extra node_loads? Developers would only need to global $node and it would either be null or populated and ready. Before creating a patch for a *possibly* terrible idea, I thought I'd raise a stick and see if it gets shot :D -- Ashraf Amayreh http://aamayreh.org
I believe any further calls to node_load with the same node id are cached. -Anthony -- Anthony Wlodarski www.thrillist.com <http://www.thrillist.com> Web Applications Developer 568 Broadway Ste. 605 New York, NY, 10012 (o) 646.786.1944 ________________________________ From: Ashraf Amayreh <mistknight@gmail.com> Reply-To: <development@drupal.org> Date: Thu, 15 Jan 2009 13:50:10 -0800 To: <development@drupal.org> Subject: [development] load node globally Hello All, Since I see so many node loads in block visibility and in modules that do $node manipulations and so forth, which would make me think that sometimes many node loads might occur on some pages and tens perhaps when you add contributed modules on that, I was wondering why not just load $node globally on node/<num>/* pages like we do with $user to avoid any extra node_loads? Developers would only need to global $node and it would either be null or populated and ready. Before creating a patch for a *possibly* terrible idea, I thought I'd raise a stick and see if it gets shot :D -- Ashraf Amayreh http://aamayreh.org
I just confirmed that node_load() stores loaded nodes in a static variable. On Jan 15, 2009, at 4:53 PM, Anthony Wlodarski wrote:
I believe any further calls to node_load with the same node id are cached.
-Anthony -- Anthony Wlodarski www.thrillist.com <http://www.thrillist.com> Web Applications Developer 568 Broadway Ste. 605 New York, NY, 10012 (o) 646.786.1944
From: Ashraf Amayreh <mistknight@gmail.com> Reply-To: <development@drupal.org> Date: Thu, 15 Jan 2009 13:50:10 -0800 To: <development@drupal.org> Subject: [development] load node globally
Hello All,
Since I see so many node loads in block visibility and in modules that do $node manipulations and so forth, which would make me think that sometimes many node loads might occur on some pages and tens perhaps when you add contributed modules on that, I was wondering why not just load $node globally on node/<num>/* pages like we do with $user to avoid any extra node_loads? Developers would only need to global $node and it would either be null or populated and ready.
Before creating a patch for a *possibly* terrible idea, I thought I'd raise a stick and see if it gets shot :D
-- Ashraf Amayreh http://aamayreh.org
On Jan 15, 2009, at 4:50 PM, Ashraf Amayreh wrote:
Hello All,
Since I see so many node loads in block visibility and in modules that do $node manipulations and so forth, which would make me think that sometimes many node loads might occur on some pages and tens perhaps when you add contributed modules on that, I was wondering why not just load $node globally on node/<num>/* pages like we do with $user to avoid any extra node_loads? Developers would only need to global $node and it would either be null or populated and ready.
node_load() stores nodes in a static variable already- see http://api.drupal.org/api/function/node_load best, a.
-- Ashraf Amayreh http://aamayreh.org
--------------------------------------------------- arthur@civicactions.com
Since I see so many node loads in block visibility and in modules that do $node manipulations and so forth, which would make me think that sometimes many node loads might occur on some pages and tens perhaps when you add contributed modules on that, I was wondering why not just load $node globally on node/<num>/* pages like we do with $user to avoid any extra node_loads?
I think it's pretty rare that the same node gets loaded twice. Well, one example might be a sidebar block with a view of full nodes or teasers in it. If one of the nodes was the URL target, it would be loaded once for the page, once for the sidebar. And how would views take advantage of it? node_load is just smart enough not to load the node twice? I think there's caching modules (e.g. the node cache feature of memcached) that do this type of thing. I'd look into cache modules if you're worried about multiple loads. Oh and of course, the built-in page cache for anon visitors makes this a non-issue if the bulk of your traffic is anon. Cheers, --fletch
In HEAD node_load() is done about 13 times during the course of a node/n page load - but as already mentioned, the static cache in node_load() prevents duplicate queries in those cases, or if it's called again from a theme. In Drupal 7, node_load_multiple() will let you pull all nodes on a page in a single query (+ 1 per hook) for node listings, and there's an active patch to cache fully loaded node objects persistently (i.e. in a cache_node table, or memcache) here: http://drupal.org/node/111127 which could use some extra benchmarks if anyone wants to help it get in. Nat
node_load() is statically cached when certain conditions are met: http://api.drupal.org/api/function/node_load/6 For D6, you can avoid node_load() in many situations by re-using the path argument: http://api.drupal.org/api/function/menu_get_object/6 For D7, node_load() will be cached: http://drupal.org/node/111127 Views avoids the use of node_load() in many cases (but not all) by directly querying only the required data in a single query. sun
-----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Dave Fletcher Sent: Thursday, January 15, 2009 10:58 PM To: development@drupal.org Subject: Re: [development] load node globally
Since I see so many node loads in block visibility and in modules that do $node manipulations and so forth, which would make me think that sometimes many node loads might occur on some pages and tens perhaps when you add contributed modules on that, I was wondering why not just load $node globally on node/<num>/* pages like we do with $user to avoid any extra node_loads?
I think it's pretty rare that the same node gets loaded twice. Well, one example might be a sidebar block with a view of full nodes or teasers in it. If one of the nodes was the URL target, it would be loaded once for the page, once for the sidebar.
And how would views take advantage of it? node_load is just smart enough not to load the node twice? I think there's caching modules (e.g. the node cache feature of memcached) that do this type of thing. I'd look into cache modules if you're worried about multiple loads. Oh and of course, the built-in page cache for anon visitors makes this a non-issue if the bulk of your traffic is anon.
Cheers,
--fletch
participants (7)
-
Anthony Wlodarski -
arthur -
Ashraf Amayreh -
Daniel F. Kudwien -
Darren Oh -
Dave Fletcher -
Nathaniel Catchpole