« Return to Thread: Performance: is better a node_load or a direct SQL query ?

Re: Performance: is better a node_load or a direct SQL query ?

by Pierre Rineau :: Rate this Message:

Reply to Author | View in Thread

Note: you must care about the context your function is executed. If it's
an AJAX callback, you might want to do your own query, because there is
no way your node might be loaded twice.

But, if you are executing this function in normal Drupal execution flow,
you have to use node_load() because there is a lot of cases in which
your node will be loaded more than once (views, some custom blocks,
access checks on url, etc...).

Pierre.

Le jeudi 02 juillet 2009 à 12:28 +0200, Pierre Rineau a écrit :

> node_load() should be better in most cases because it uses an internal
> cache to make sure a node is never loaded twice.
>
> This ensures no SQL query repetition, that are often the worst nightmare
> for performance.
>
> Pierre.
>
> Le jeudi 02 juillet 2009 à 12:20 +0200, Michel Morelli a écrit :
> > Hi all. I have a content type with 15+ fields. In some situations I need
> > to retrieve only 3 fields.
> >
> > So, is better (perfomance, security, portability, etc etc) a call to
> > node_load() function or a direct SQL query on the right table ?
> >
> > M.
> >
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]

--
[ Drupal support list | http://lists.drupal.org/ ]

 « Return to Thread: Performance: is better a node_load or a direct SQL query ?