[development] load node globally
Daniel F. Kudwien
news at unleashedmind.com
Thu Jan 15 22:37:45 UTC 2009
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 at drupal.org
> [mailto:development-bounces at drupal.org] On Behalf Of Dave Fletcher
> Sent: Thursday, January 15, 2009 10:58 PM
> To: development at 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
>
More information about the development
mailing list