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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | user_titles-beta5-caching-917334-3.patch | 3.23 KB | cannandev |
| #2 | user_titles-caching-917334-1.patch | 3.82 KB | cannandev |
| #1 | user_titles-caching-get_titles.patch | 2.32 KB | cannandev |
| user_title_get_titles_fix.diff | 1.09 KB | cannandev |
Comments
Comment #1
cannandev commentedWoops,
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.
Comment #2
cannandev commentedAlso 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.
Comment #3
cannandev commentedThis 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.