Seeing a bunch of calls to user_titles_get_titles() which calls the query
SELECT title, value, tid FROM {user_titles} ORDER BY value DESC
for each board post. Started to implement static caching but noticed that user_titles_set_titles($titles) was already doing a variable_set('user_titles', $titles) to store titles in the database. So decided to use variable_get() for the 'user_titles' variable instead of a static variable which reduced query calls to 0 instead of more than 30.

Comments

cannandev’s picture

StatusFileSize
new2.32 KB

Woops,

Was using a previous version of User Titles module (6.x-0.1). Upgraded to version 6.x-1.x-dev. Since this version does not do a variable_set('user_titles', $titles) to store titles in the database, implemented static caching in user_titles_get_titles(). Instead of making an additional database call for user_titles by tid, we pull it from the $result array. Also added the $reset parameter to all database queries that change {user_titles}. When true, reloads the titles and bypasses caching.

cannandev’s picture

Title: Add caching to user_titles_get_titles() » Add caching to user_titles_get_titles() and user_titles_get_user_title_info()
StatusFileSize
new3.82 KB

Also added static caching to the user_titles_get_user_title_info(). Checks if the the $user->uid was cached first. Then grabs the title object that was already set or from the database. Now returns false an empty $tid instead of returning the $title object from user_titles_get_titles().
Before the patch, the query on {user_titles_users} was called up to 12 times for each uid and was reduced to one call per uid after.

cannandev’s picture

Title: Add caching to user_titles_get_titles() and user_titles_get_user_title_info() » Static caching user_titles_get_titles()
Version: 6.x-1.x-dev » 6.x-1.0-beta5
StatusFileSize
new3.23 KB

This patch implements static caching on user_titles_get_titles() for beta5 version. Also, once {user_titles} is updated, or a title is added or deleted, user_titles_get_titles(NULL, TRUE) should be called to bypass the cache and populate the $titles object with the latest values from the database.