The attached patch uses drupal's caching API to cache the results of user_relationships_load_all_for_user($uid) and user_relationships_relationship_load($rid) across page loads.
I also changed the implementation of user_relationships_relationship_type_load() to not go to the database at all. It now calls user_relationships_relationship_types_load() and searches through the array that's returned. This doesn't seem like it would save much, but it turns out that something somewhere (at least on our site) is calling user_relationships_relationship_type_load() with an array('rtid' => '') 6 times on every page load, resulting in 6 useless queries on every page. Also, legitimate types were being loaded and cached twice - once in user_relationships_relationship_types_load() and again in user_relationships_relationship_type_load(). It wasn't a huge hit, but this way there are no extra queries or caching.
Note: If you're not using memcache, you'll need to update your schema to add the cache_user_relationships table.
IMPORTANT CAVEAT FOR MEMCACHE USERS:
If you have the memcache module installed, then the cache will not be properly cleared when you delete a user or a relationship type. This is a result of memcache's implementation of cache_clear_all() not honoring the third (wildcard) parameter. The User Relationships README.txt has instructions on how to clear your cache if you have memcache installed, so stale (incorrect) data isn't cached indefinitely.
| Comment | File | Size | Author |
|---|---|---|---|
| urcache.patch | 12.02 KB | prfctns6@gmail.com |
Comments
Comment #1
sprsquish commentedHA! I was just talking about needing to write caching into the module.
You win.
BTW, memcache's implementation of cache_clear_all doesn't honor the wildcard because memcache itself doesn't. There's no way to do wildcards in IDs in memcache. I gotta say I'm a little curious as to why they wouldn't treat the wildcard as $cid='*'
Comment #2
prfctns6@gmail.com commentedThe patch has been committed.
Comment #3
gwen commented