Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/08/2011 02:57:38 AM (13 years ago)
Author:
boonebgorges
Message:

Introduces automatic meta cache features.
Introduces bp_update_meta_cache(), for collecting all metadata associated with an object or with multiple objects in one fell swoop, and adding it to the WP cache for quicker access later
Introduces bp_groups_update_meta_cache(), for collecting groupmeta at the beginning of a group loop
Modifies the BP_Groups_Group object so that groupmeta is fetched in the populate() and get() methods
Fixes #3799

File:
1 edited

Legend:

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

    r5431 r5460  
    3131        global $wpdb, $bp;
    3232
    33         if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.*, gm.meta_value as last_activity, gm2.meta_value as total_member_count FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm, {$bp->groups->table_name_groupmeta} gm2 WHERE g.id = gm.group_id AND g.id = gm2.group_id AND gm.meta_key = 'last_activity' AND gm2.meta_key = 'total_member_count' AND g.id = %d", $this->id ) ) ) {
     33        if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ) ) {         
     34            bp_groups_update_meta_cache( $this->id );
     35                       
    3436            $this->id                 = $group->id;
    3537            $this->creator_id         = $group->creator_id;
     
    4042            $this->enable_forum       = $group->enable_forum;
    4143            $this->date_created       = $group->date_created;
    42             $this->last_activity      = $group->last_activity;
    43             $this->total_member_count = $group->total_member_count;
     44            $this->last_activity      = groups_get_groupmeta( $this->id, 'last_activity' );
     45            $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
    4446            $this->is_member          = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id );
    4547
     
    368370        $total_groups     = $wpdb->get_var( $total_groups_sql );
    369371
     372        $group_ids = array();
     373        foreach ( (array)$paged_groups as $group ) {
     374            $group_ids[] = $group->id;
     375        }
     376       
    370377        /* Populate some extra information instead of querying each time in the loop */
    371378        if ( !empty( $populate_extras ) ) {
    372             $group_ids = array();
    373             foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    374379            $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    375380            $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $type );
    376381        }
     382       
     383        // Grab all groupmeta
     384        bp_groups_update_meta_cache( $group_ids );
    377385
    378386        unset( $sql, $total_sql );
Note: See TracChangeset for help on using the changeset viewer.