Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/26/2014 09:37:39 PM (12 years ago)
Author:
r-a-y
Message:

Add object caching when fetching the active notice.

This commit:

  • Introduces a new hook - 'messages_notice_before_delete' to do something before a notice is deleted
  • Adds object caching to the BP_Messages_Notice::get_active() method
  • Adds a cache invalidation function to bp-messages-cache.php
  • Adds a unit test

Fixes #5419

File:
1 edited

Legend:

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

    r7969 r7994  
    578578                global $wpdb, $bp;
    579579
     580                do_action( 'messages_notice_before_delete', $this );
     581
    580582                $sql = $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id );
    581583
     
    644646         */
    645647        public static function get_active() {
    646                 global $wpdb, $bp;
    647 
    648                 $notice_id = $wpdb->get_var( "SELECT id FROM {$bp->messages->table_name_notices} WHERE is_active = 1" );
    649 
    650                 return new BP_Messages_Notice( $notice_id );
     648                $notice = wp_cache_get( 'active_notice', 'bp_messages' );
     649
     650                if ( false === $notice ) {
     651                        global $wpdb, $bp;
     652
     653                        $notice_id = $wpdb->get_var( "SELECT id FROM {$bp->messages->table_name_notices} WHERE is_active = 1" );
     654                        $notice    = new BP_Messages_Notice( $notice_id );
     655
     656                        wp_cache_set( 'active_notice', $notice, 'bp_messages' );
     657                }
     658
     659                return $notice;
    651660        }
    652661}
Note: See TracChangeset for help on using the changeset viewer.