How to remove duplicate query calls?

Events happening in the community are now at Drupal community events on www.drupal.org.
sifuhall's picture

I have a big site and recently converted to Drupal.

My forums (using drupal advanced forum) are very slow and my users are unhappy.

Installed the devel module I can see that I have a tremendous amount of duplicate queries, but how can I eliminate them?

Some queries are called over 60 times!

Devel reports:

Executed 1347 queries in 5666.48 milliseconds
Page execution time was 7213.35 ms.

Comments

static

mikeytown2's picture

Use a static variable to store the query results. Use the where clause of your query as the array key.
http://php.net/variables.scope#language.variables.scope.static

Good way to use them (with a reset argument)
http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func...

Bad way (no reset)
http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func...

Thanks for the reply! For

sifuhall's picture

Thanks for the reply!

For example, on my initial forums page (using advanced forum) I see that

SELECT r.rid, r.name FROM role r INNER JOIN users_roles ur ON ur.rid = r.rid WHERE ur.uid = 1

is called by user_load at least 66 times (according to devel)

How would I use a static var to reduce the number of times this query is called?

Core patch

mikeytown2's picture

Here is the issue for user_load
http://drupal.org/node/281596

Pressflow doesn't static cache here so a change like this will require lots of testing on your end if you wish to use it.
http://bazaar.launchpad.net/~pressflow/pressflow/6/annotate/head%3A/modu...

The other plan is to look upstream and see what is calling all the user_loads & introduce caching there.

MySQL cache

jcisio's picture

Turn MySQL query cache on. If you have 66 queries in one page view, 65 last ones cost nothing (less than 1 ms for all of them).

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: