Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/13/2015 05:24:33 PM (11 years ago)
Author:
boonebgorges
Message:

Cache the results of BP_Messages_Thread::get_recipients().

This can save a large number of queries on certain inbox views.

Props wpdennis.
See #6221. Fixes #6220.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-classes.php

    r9471 r9482  
    214214                global $wpdb;
    215215
    216                 $bp = buddypress();
    217 
    218                 $recipients = array();
    219                 $results    = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
    220 
    221                 foreach ( (array) $results as $recipient ) {
    222                         $recipients[$recipient->user_id] = $recipient;
     216                $recipients = wp_cache_get( 'thread_recipients_' . $this->thread_id, 'bp_messages' );
     217                if ( false === $recipients ) {
     218                        $bp = buddypress();
     219
     220                        $recipients = array();
     221                        $results    = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
     222
     223                        foreach ( (array) $results as $recipient ) {
     224                                $recipients[ $recipient->user_id ] = $recipient;
     225                        }
     226
     227                        wp_cache_set( 'thread_recipients_' . $this->thread_id, $recipients, 'bp_messages' );
    223228                }
    224229
Note: See TracChangeset for help on using the changeset viewer.