Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
You could do several things to make _user_stats_last_post faster
First:
use db_query_range($sql, 0, 1) instead of db_query, this might be faster
472 $max_node = db_result(db_query($sql, 1, $uid));
473 $sql = "SELECT MAX(timestamp) FROM {comments} c
474 INNER JOIN {node} n ON c.nid=n.nid
475 WHERE c.status=%d AND c.uid=%d";
476 if (!empty($post_count_content_types)) {
477 $where = ' AND n.type IN ('. $content_types .')';
478 $sql .= $where;
479 }
Only join if $post_count_content_types is not empty.
Comment | File | Size | Author |
---|---|---|---|
#8 | 829134-performance-2.patch | 1.98 KB | Liam McDermott |
#2 | 829134-performance.patch | 1.14 KB | dawehner |
Comments
Comment #1
Witch CreditAttribution: Witch commentedHi dereine,
i am interested in your perfomance suggestions. Did you patched the module and may you post a patch or the patched version?
Thank you.
Comment #2
dawehnerhere is one. This patch is not tested, so someone should do this :)
Comment #3
dawehnerPS: This patch works fine here.
Comment #4
Liam McDermott CreditAttribution: Liam McDermott commentedThanks for bumping this, I meant to look at it ages ago!
Looks good, I should be able to test and commit it tomorrow.
Comment #5
introfini CreditAttribution: introfini commentedCan this please be committed . It's working for me too.
Comment #6
Liam McDermott CreditAttribution: Liam McDermott commentedSorry for still not getting to this, have been working remotely and haven't had a chance to setup a local test install with Xdebug and all that good stuff.
Before applying the patch I thought I'd have a look at using
db_query_range
instead ofdb_query
, unfortunately it's slightly slower.Am expecting the patch is going to make things faster, however. Hopefully, I actually will get to look at the patch tomorrow. Thanks for being patient. :)
Comment #7
Liam McDermott CreditAttribution: Liam McDermott commentedThe patch doesn't work if you have a content type selected on the User Stats configuration page. It tries to add two WHERE clauses to the query:
I'm going to think of a way to fix this, then test the performance of the patch.
Comment #8
Liam McDermott CreditAttribution: Liam McDermott commentedAttached is the patch that's being committed. I fixed the problem with the WHERE clause being added twice and added some logic to also exclude the JOIN when all node types are selected on the config page (since it's logically equivalent to none).
Note the call to
node_get_types()
, I checked and this caches its results and is called earlier in the page, so the cost is almost nothing.** EDIT **
Forgot to mention: testing showed about a 1% - 2% saving in page load times. Doesn't seem like much, but will soon add up. Thanks very much for the patch!
Comment #9
Liam McDermott CreditAttribution: Liam McDermott commented