Ticket #3799: 3799.01.patch
File 3799.01.patch, 6.5 KB (added by , 13 years ago) |
---|
-
bp-core/bp-core-cache.php
diff --git a/bp-core/bp-core-cache.php b/bp-core/bp-core-cache.php index 0c30cb1..640b109 100644
a b function bp_core_clear_user_object_cache( $user_id ) { 48 48 add_action( 'wp_login', 'bp_core_clear_cache' ); 49 49 add_action( 'bp_core_render_notice', 'bp_core_clear_cache' ); 50 50 51 /** 52 * Update the metadata cache for the specified objects. 53 * 54 * @since 1.6 55 * @uses $wpdb WordPress database object for queries. 56 * @uses $bp BuddyPress global object. 57 * 58 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 59 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for 60 * @return mixed Metadata cache for the specified objects, or false on failure. 61 */ 62 function bp_update_meta_cache( $args = array() ) { 63 global $bp, $wpdb; 64 65 $defaults = array( 66 'object_ids' => array(), 67 'object_type' => '', 68 'meta_table' => '', 69 'object_column' => '', 70 'cache_key_prefix' => '' 71 ); 72 $r = wp_parse_args( $args, $defaults ); 73 extract( $r ); 74 75 if ( empty( $object_ids ) || empty( $object_type ) || empty( $meta_table ) ) { 76 return false; 77 } 78 79 if ( empty( $cache_key_prefix ) ) { 80 $cache_key_prefix = $meta_table; 81 } 82 83 if ( empty( $object_column ) ) { 84 $object_column = $object_type . '_id'; 85 } 86 87 if ( !is_array( $object_ids ) ) { 88 $object_ids = preg_replace( '|[^0-9,]|', '', $object_ids ); 89 $object_ids = explode( ',', $object_ids ); 90 } 91 92 $object_ids = array_map( 'intval', $object_ids ); 93 94 $cache = array(); 95 96 // Get meta info 97 $id_list = join( ',', $object_ids ); 98 $meta_list = $wpdb->get_results( $wpdb->prepare( "SELECT $object_column, meta_key, meta_value FROM $meta_table WHERE group_id IN ($id_list)" ), ARRAY_A ); 99 100 if ( !empty( $meta_list ) ) { 101 foreach ( $meta_list as $metarow ) { 102 $mpid = intval( $metarow[$object_column] ); 103 $mkey = $metarow['meta_key']; 104 $mval = $metarow['meta_value']; 105 106 // Force subkeys to be array type: 107 if ( !isset( $cache[$mpid] ) || !is_array( $cache[$mpid] ) ) 108 $cache[$mpid] = array(); 109 if ( !isset( $cache[$mpid][$mkey] ) || !is_array( $cache[$mpid][$mkey] ) ) 110 $cache[$mpid][$mkey] = array(); 111 112 // Add a value to the current pid/key: 113 $cache[$mpid][$mkey][] = $mval; 114 } 115 } 116 117 foreach ( $object_ids as $id ) { 118 if ( ! isset($cache[$id]) ) 119 $cache[$id] = array(); 120 121 foreach( $cache[$id] as $meta_key => $meta_value ) { 122 //var_dump( $cache_key_prefix . '_' . $id . '_' . $meta_key ); 123 wp_cache_set( $cache_key_prefix . '_' . $id . '_' . $meta_key, $meta_value, 'bp' ); 124 } 125 } 126 127 return $cache; 128 } 129 51 130 ?> 131 No newline at end of file -
bp-groups/bp-groups-cache.php
diff --git a/bp-groups/bp-groups-cache.php b/bp-groups/bp-groups-cache.php index 908df53..1d8fcef 100644
a b 12 12 // Exit if accessed directly 13 13 if ( !defined( 'ABSPATH' ) ) exit; 14 14 15 function bp_groups_update_meta_cache( $group_ids = false ) { 16 global $bp; 17 18 $cache_args = array( 19 'object_ids' => $group_ids, 20 'object_type' => $bp->groups->id, 21 'object_column' => 'group_id', 22 'meta_table' => $bp->groups->table_name_groupmeta, 23 'cache_key_prefix' => 'bp_groups_groupmeta' 24 ); 25 26 bp_update_meta_cache( $cache_args ); 27 } 28 15 29 function groups_clear_group_object_cache( $group_id ) { 16 30 wp_cache_delete( 'bp_total_group_count', 'bp' ); 17 31 } -
bp-groups/bp-groups-classes.php
diff --git a/bp-groups/bp-groups-classes.php b/bp-groups/bp-groups-classes.php index 41128a9..2d9a91a 100644
a b Class BP_Groups_Group { 30 30 function populate() { 31 31 global $wpdb, $bp; 32 32 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 34 36 $this->id = $group->id; 35 37 $this->creator_id = $group->creator_id; 36 38 $this->name = stripslashes($group->name); … … Class BP_Groups_Group { 39 41 $this->status = $group->status; 40 42 $this->enable_forum = $group->enable_forum; 41 43 $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' ); 44 46 $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id ); 45 47 46 48 // Get group admins and mods -
bp-groups/bp-groups-functions.php
diff --git a/bp-groups/bp-groups-functions.php b/bp-groups/bp-groups-functions.php index 522adbe..fbb1911 100644
a b function groups_get_group( $args = '' ) { 46 46 47 47 if ( !$group = wp_cache_get( $cache_key, 'bp' ) ) { 48 48 $group = new BP_Groups_Group( $group_id, true, $load_users ); 49 wp_cache_set( $cache_key, $group, 'bp' ); 49 wp_cache_set( $cache_key, $group, 'bp' ); 50 50 } 51 51 52 52 return apply_filters( 'groups_get_group', $group ); … … function groups_get_groupmeta( $group_id, $meta_key = '') { 918 918 if ( !empty($meta_key) ) { 919 919 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 920 920 921 $metas = wp_cache_get( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' ); 921 $metas = wp_cache_get( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' ); 922 922 if ( false === $metas ) { 923 923 $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key) ); 924 924 wp_cache_set( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, $metas, 'bp' ); -
bp-groups/bp-groups-loader.php
diff --git a/bp-groups/bp-groups-loader.php b/bp-groups/bp-groups-loader.php index da31457..cd61481 100644
a b 14 14 if ( !defined( 'ABSPATH' ) ) exit; 15 15 16 16 class BP_Groups_Component extends BP_Component { 17 var $cached_meta = array(); 17 18 18 19 /** 19 20 * Start the groups component creation process