Posted by sifuhall on December 11, 2010 at 9:19pm
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
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
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
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
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).