Ticket #5733: 5733.04.patch
File 5733.04.patch, 48.8 KB (added by , 8 years ago) |
---|
-
src/bp-activity/bp-activity-admin.php
542 542 $result = $activity->save(); 543 543 544 544 // Clear the activity stream first page cache, in case this activity's timestamp was changed 545 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );545 bp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 546 546 547 547 // Check for any error during activity save 548 548 if ( false === $result ) -
src/bp-activity/bp-activity-cache.php
42 42 * @param BP_Activity_Activity $activity 43 43 */ 44 44 function bp_activity_clear_cache_for_activity( $activity ) { 45 wp_cache_delete( $activity->id, 'bp_activity' );45 bp_cache_delete( $activity->id, 'bp_activity' ); 46 46 } 47 47 add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' ); 48 48 … … 55 55 */ 56 56 function bp_activity_clear_cache_for_deleted_activity( $deleted_ids ) { 57 57 foreach ( (array) $deleted_ids as $deleted_id ) { 58 wp_cache_delete( $deleted_id, 'bp_activity' );58 bp_cache_delete( $deleted_id, 'bp_activity' ); 59 59 } 60 60 } 61 61 add_action( 'bp_activity_deleted_activities', 'bp_activity_clear_cache_for_deleted_activity' ); -
src/bp-activity/bp-activity-classes.php
137 137 public function populate() { 138 138 global $wpdb, $bp; 139 139 140 $row = wp_cache_get( $this->id, 'bp_activity' );140 $row = bp_cache_get( $this->id, 'bp_activity' ); 141 141 142 142 if ( false === $row ) { 143 143 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ); 144 144 145 wp_cache_set( $this->id, $row, 'bp_activity' );145 bp_cache_set( $this->id, $row, 'bp_activity' ); 146 146 } 147 147 148 148 if ( ! empty( $row ) ) { … … 645 645 // Put that data into the placeholders created earlier, 646 646 // and add it to the cache 647 647 foreach ( (array) $queried_adata as $adata ) { 648 wp_cache_set( $adata->id, $adata, 'bp_activity' );648 bp_cache_set( $adata->id, $adata, 'bp_activity' ); 649 649 } 650 650 } 651 651 652 652 // Now fetch data from the cache 653 653 foreach ( $activity_ids as $activity_id ) { 654 $activities[] = wp_cache_get( $activity_id, 'bp_activity' );654 $activities[] = bp_cache_get( $activity_id, 'bp_activity' ); 655 655 } 656 656 657 657 // Then fetch user data … … 1269 1269 $top_level_parent_id = $activity_id; 1270 1270 } 1271 1271 1272 $comments = wp_cache_get( $activity_id, 'bp_activity_comments' );1272 $comments = bp_cache_get( $activity_id, 'bp_activity_comments' ); 1273 1273 1274 1274 // We store the string 'none' to cache the fact that the 1275 1275 // activity item has no comments … … 1394 1394 $cache_value = $comments; 1395 1395 } 1396 1396 1397 wp_cache_set( $activity_id, $cache_value, 'bp_activity_comments' );1397 bp_cache_set( $activity_id, $cache_value, 'bp_activity_comments' ); 1398 1398 } 1399 1399 1400 1400 return $comments; -
src/bp-activity/bp-activity-functions.php
1396 1396 * @see BP_Activity_Activity::get() For more information on accepted arguments 1397 1397 * and the format of the returned value. 1398 1398 * @uses wp_parse_args() 1399 * @uses wp_cache_get()1400 * @uses wp_cache_set()1399 * @uses bp_cache_get() 1400 * @uses bp_cache_set() 1401 1401 * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity} 1402 1402 * @uses apply_filters_ref_array() To call the 'bp_activity_get' hook. 1403 1403 * … … 1441 1441 // Attempt to return a cached copy of the first page of sitewide activity. 1442 1442 if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['scope'] )&& empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) { 1443 1443 1444 $activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' );1444 $activity = bp_cache_get( 'bp_activity_sitewide_front', 'bp' ); 1445 1445 if ( false === $activity ) { 1446 1446 1447 1447 $activity = BP_Activity_Activity::get( array( … … 1462 1462 'count_total' => $r['count_total'], 1463 1463 ) ); 1464 1464 1465 wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );1465 bp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' ); 1466 1466 } 1467 1467 1468 1468 } else { … … 1561 1561 * @uses wp_parse_args() 1562 1562 * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity} 1563 1563 * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity} 1564 * @uses wp_cache_delete()1564 * @uses bp_cache_delete() 1565 1565 * @uses do_action() To call the 'bp_activity_add' hook 1566 1566 * 1567 1567 * @param array $args { … … 1646 1646 // If this is an activity comment, rebuild the tree 1647 1647 if ( 'activity_comment' === $activity->type ) { 1648 1648 // Also clear the comment cache for the parent activity ID 1649 wp_cache_delete( $activity->item_id, 'bp_activity_comments' );1649 bp_cache_delete( $activity->item_id, 'bp_activity_comments' ); 1650 1650 1651 1651 BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id ); 1652 1652 } 1653 1653 1654 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );1654 bp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 1655 1655 1656 1656 /** 1657 1657 * Fires at the end of the execution of adding a new activity item, before returning the new activity item ID. … … 2002 2002 * @uses bp_activity_add() 2003 2003 * @uses apply_filters() To call the 'bp_activity_comment_action' hook. 2004 2004 * @uses apply_filters() To call the 'bp_activity_comment_content' hook. 2005 * @uses wp_cache_delete()2005 * @uses bp_cache_delete() 2006 2006 * @uses do_action() To call the 'bp_activity_comment_posted' hook. 2007 2007 * 2008 2008 * @param array $args { … … 2086 2086 ) ); 2087 2087 2088 2088 // Comment caches are stored only with the top-level item 2089 wp_cache_delete( $activity_id, 'bp_activity_comments' );2089 bp_cache_delete( $activity_id, 'bp_activity_comments' ); 2090 2090 2091 2091 // Walk the tree to clear caches for all parent items 2092 2092 $clear_id = $r['parent_id']; 2093 2093 while ( $clear_id != $activity_id ) { 2094 2094 $clear_object = new BP_Activity_Activity( $clear_id ); 2095 wp_cache_delete( $clear_id, 'bp_activity' );2095 bp_cache_delete( $clear_id, 'bp_activity' ); 2096 2096 $clear_id = intval( $clear_object->secondary_item_id ); 2097 2097 } 2098 wp_cache_delete( $activity_id, 'bp_activity' );2098 bp_cache_delete( $activity_id, 'bp_activity' ); 2099 2099 2100 2100 /** 2101 2101 * Fires near the end of an activity comment posting, before the returning of the comment ID. … … 2185 2185 * @uses bp_delete_user_meta() 2186 2186 * @uses do_action() To call the 'bp_activity_delete' hook. 2187 2187 * @uses do_action() To call the 'bp_activity_deleted_activities' hook. 2188 * @uses wp_cache_delete()2188 * @uses bp_cache_delete() 2189 2189 * 2190 2190 * @param array $args To delete specific activity items, use 2191 2191 * $args = array( 'id' => $ids ); … … 2257 2257 */ 2258 2258 do_action( 'bp_activity_deleted_activities', $activity_ids_deleted ); 2259 2259 2260 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );2260 bp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2261 2261 2262 2262 return true; 2263 2263 } … … 2398 2398 } 2399 2399 2400 2400 // Purge comment cache for the root activity update 2401 wp_cache_delete( $activity_id, 'bp_activity_comments' );2401 bp_cache_delete( $activity_id, 'bp_activity_comments' ); 2402 2402 2403 2403 // Recalculate the comment tree 2404 2404 BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id ); … … 2632 2632 $activity->is_spam = 1; 2633 2633 2634 2634 // Clear the activity stream first page cache 2635 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );2635 bp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2636 2636 2637 2637 // Clear the activity comment cache for this activity item 2638 wp_cache_delete( $activity->id, 'bp_activity_comments' );2638 bp_cache_delete( $activity->id, 'bp_activity_comments' ); 2639 2639 2640 2640 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity 2641 2641 if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { … … 2679 2679 $activity->is_spam = 0; 2680 2680 2681 2681 // Clear the activity stream first page cache 2682 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );2682 bp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2683 2683 2684 2684 // Clear the activity comment cache for this activity item 2685 wp_cache_delete( $activity->id, 'bp_activity_comments' );2685 bp_cache_delete( $activity->id, 'bp_activity_comments' ); 2686 2686 2687 2687 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity 2688 2688 if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { -
src/bp-activity/bp-activity-loader.php
362 362 363 363 parent::setup_actions(); 364 364 } 365 366 /** 367 * Setup cache groups 368 * 369 * @since BuddyPress (2.2.0) 370 */ 371 public function setup_cache_groups() { 372 373 // Global groups 374 wp_cache_add_global_groups( array( 375 'bp_activity', 376 'bp_activity_comments', 377 'activity_meta' 378 ) ); 379 380 parent::setup_cache_groups(); 381 } 365 382 } 366 383 367 384 /** -
src/bp-blogs/bp-blogs-cache.php
44 44 */ 45 45 function bp_blogs_clear_blog_object_cache( $blog_id = 0, $user_id = 0 ) { 46 46 if ( ! empty( $user_id ) ) { 47 wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );48 wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );47 bp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' ); 48 bp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' ); 49 49 } 50 50 51 wp_cache_delete( 'bp_total_blogs', 'bp' );51 bp_cache_delete( 'bp_total_blogs', 'bp' ); 52 52 } 53 53 54 54 // List actions to clear object caches on -
src/bp-blogs/bp-blogs-functions.php
128 128 foreach ( (array) $blog_ids as $blog_id ) { 129 129 130 130 // Ensure that the cache is clear after the table TRUNCATE above 131 wp_cache_delete( $blog_id, 'blog_meta' );131 bp_cache_delete( $blog_id, 'blog_meta' ); 132 132 133 133 // Get all users 134 134 $users = get_users( array( … … 1144 1144 * @return int $count Total blog count. 1145 1145 */ 1146 1146 function bp_blogs_total_blogs() { 1147 $count = wp_cache_get( 'bp_total_blogs', 'bp' );1147 $count = bp_cache_get( 'bp_total_blogs', 'bp' ); 1148 1148 1149 1149 if ( false === $count ) { 1150 1150 $blogs = BP_Blogs_Blog::get_all(); 1151 1151 $count = $blogs['total']; 1152 wp_cache_set( 'bp_total_blogs', $count, 'bp' );1152 bp_cache_set( 'bp_total_blogs', $count, 'bp' ); 1153 1153 } 1154 1154 return $count; 1155 1155 } … … 1173 1173 return 0; 1174 1174 } 1175 1175 1176 $count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' );1176 $count = bp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ); 1177 1177 if ( false === $count ) { 1178 1178 $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id ); 1179 wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );1179 bp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' ); 1180 1180 } 1181 1181 1182 1182 return $count; -
src/bp-blogs/bp-blogs-loader.php
272 272 } 273 273 274 274 /** 275 * Setup cache groups 276 * 277 * @since BuddyPress (2.2.0) 278 */ 279 public function setup_cache_groups() { 280 281 // Global groups 282 wp_cache_add_global_groups( array( 283 'blog_meta' 284 ) ); 285 286 parent::setup_cache_groups(); 287 } 288 289 /** 275 290 * Set up the tracking arguments for the 'post' post type. 276 291 * 277 292 * @since BuddyPress (2.2.0) -
src/bp-friends/bp-friends-cache.php
23 23 if ( !$friendship = new BP_Friends_Friendship( $friendship_id ) ) 24 24 return false; 25 25 26 wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );27 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );26 bp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' ); 27 bp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' ); 28 28 } 29 29 30 30 // List actions to clear object caches on … … 39 39 * @param int $friend_user_id The user ID not initiating the friendship 40 40 */ 41 41 function bp_friends_clear_request_cache( $friend_user_id ) { 42 wp_cache_delete( $friend_user_id, 'bp_friends_requests' );42 bp_cache_delete( $friend_user_id, 'bp_friends_requests' ); 43 43 } 44 44 45 45 /** -
src/bp-friends/bp-friends-classes.php
240 240 * @return array|bool An array of user IDs, or false if none are found. 241 241 */ 242 242 public static function get_friendship_request_user_ids( $user_id ) { 243 $friend_requests = wp_cache_get( $user_id, 'bp_friends_requests' );243 $friend_requests = bp_cache_get( $user_id, 'bp_friends_requests' ); 244 244 245 245 if ( false === $friend_requests ) { 246 246 global $wpdb, $bp; 247 247 248 248 $friend_requests = $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) ); 249 249 250 wp_cache_set( $user_id, $friend_requests, 'bp_friends_requests' );250 bp_cache_set( $user_id, $friend_requests, 'bp_friends_requests' ); 251 251 } 252 252 253 253 return $friend_requests; -
src/bp-friends/bp-friends-loader.php
239 239 240 240 parent::setup_title(); 241 241 } 242 243 /** 244 * Setup cache groups 245 * 246 * @since BuddyPress (2.2.0) 247 */ 248 public function setup_cache_groups() { 249 250 // Global groups 251 wp_cache_add_global_groups( array( 252 'bp_friend_requests' 253 ) ); 254 255 parent::setup_cache_groups(); 256 } 242 257 } 243 258 244 259 /** -
src/bp-friends/bp-friends-template.php
73 73 */ 74 74 function bp_friends_random_friends() { 75 75 76 if ( !$friend_ids = wp_cache_get( 'friends_friend_ids_' . bp_displayed_user_id(), 'bp' ) ) {76 if ( !$friend_ids = bp_cache_get( 'friends_friend_ids_' . bp_displayed_user_id(), 'bp' ) ) { 77 77 $friend_ids = BP_Friends_Friendship::get_random_friends( bp_displayed_user_id() ); 78 wp_cache_set( 'friends_friend_ids_' . bp_displayed_user_id(), $friend_ids, 'bp' );78 bp_cache_set( 'friends_friend_ids_' . bp_displayed_user_id(), $friend_ids, 'bp' ); 79 79 } ?> 80 80 81 81 <div class="info-group"> … … 121 121 */ 122 122 function bp_friends_random_members( $total_members = 5 ) { 123 123 124 if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) {124 if ( !$user_ids = bp_cache_get( 'friends_random_users', 'bp' ) ) { 125 125 $user_ids = BP_Core_User::get_users( 'random', $total_members ); 126 wp_cache_set( 'friends_random_users', $user_ids, 'bp' );126 bp_cache_set( 'friends_random_users', $user_ids, 'bp' ); 127 127 } 128 128 129 129 ?> … … 494 494 function bp_get_friend_friendship_id() { 495 495 global $members_template; 496 496 497 if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {497 if ( !$friendship_id = bp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) { 498 498 $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() ); 499 wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );499 bp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' ); 500 500 } 501 501 502 502 /** … … 523 523 function bp_get_friend_accept_request_link() { 524 524 global $members_template; 525 525 526 if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {526 if ( !$friendship_id = bp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) { 527 527 $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() ); 528 wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );528 bp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' ); 529 529 } 530 530 531 531 /** … … 552 552 function bp_get_friend_reject_request_link() { 553 553 global $members_template; 554 554 555 if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {555 if ( !$friendship_id = bp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) { 556 556 $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() ); 557 wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );557 bp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' ); 558 558 } 559 559 560 560 /** -
src/bp-groups/bp-groups-activity.php
213 213 // rather than manually 214 214 $uncached_ids = array(); 215 215 foreach ( $group_ids as $group_id ) { 216 if ( false === wp_cache_get( $group_id, 'bp_groups' ) ) {216 if ( false === bp_cache_get( $group_id, 'bp_groups' ) ) { 217 217 $uncached_ids[] = $group_id; 218 218 } 219 219 } … … 224 224 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); 225 225 $groups = $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name} WHERE id IN ({$uncached_ids_sql})" ); 226 226 foreach ( $groups as $group ) { 227 wp_cache_set( $group->id, $group, 'bp_groups' );227 bp_cache_set( $group->id, $group, 'bp_groups' ); 228 228 } 229 229 } 230 230 } -
src/bp-groups/bp-groups-cache.php
48 48 * @param $group_id Not used. 49 49 */ 50 50 function groups_clear_group_object_cache( $group_id ) { 51 wp_cache_delete( 'bp_total_group_count', 'bp' );51 bp_cache_delete( 'bp_total_group_count', 'bp' ); 52 52 } 53 53 add_action( 'groups_group_deleted', 'groups_clear_group_object_cache' ); 54 54 add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' ); … … 64 64 * @param int $group_id The group being edited. 65 65 */ 66 66 function bp_groups_delete_group_cache( $group_id = 0 ) { 67 wp_cache_delete( $group_id, 'bp_groups' );67 bp_cache_delete( $group_id, 'bp_groups' ); 68 68 } 69 69 add_action( 'groups_delete_group', 'bp_groups_delete_group_cache' ); 70 70 add_action( 'groups_update_group', 'bp_groups_delete_group_cache' ); … … 77 77 * @since BuddyPress (2.0.0) 78 78 */ 79 79 function bp_groups_delete_group_cache_on_metadata_change( $meta_id, $group_id ) { 80 wp_cache_delete( $group_id, 'bp_groups' );80 bp_cache_delete( $group_id, 'bp_groups' ); 81 81 } 82 82 add_action( 'updated_group_meta', 'bp_groups_delete_group_cache_on_metadata_change', 10, 2 ); 83 83 add_action( 'added_group_meta', 'bp_groups_delete_group_cache_on_metadata_change', 10, 2 ); … … 121 121 * @param int $user_id The user ID. 122 122 */ 123 123 function bp_groups_clear_invite_count_for_user( $user_id ) { 124 wp_cache_delete( $user_id, 'bp_group_invite_count' );124 bp_cache_delete( $user_id, 'bp_group_invite_count' ); 125 125 } 126 126 add_action( 'groups_accept_invite', 'bp_groups_clear_invite_count_for_user' ); 127 127 add_action( 'groups_reject_invite', 'bp_groups_clear_invite_count_for_user' ); … … 164 164 * @param int $user_id The user ID. 165 165 */ 166 166 function groups_clear_group_user_object_cache( $group_id, $user_id ) { 167 wp_cache_delete( 'bp_total_groups_for_user_' . $user_id, 'bp' );167 bp_cache_delete( 'bp_total_groups_for_user_' . $user_id, 'bp' ); 168 168 } 169 169 add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 ); 170 170 add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 ); … … 181 181 * @param int $group_id The group ID. 182 182 */ 183 183 function groups_clear_group_administrator_cache( $group_id ) { 184 wp_cache_delete( $group_id, 'bp_group_admins' );184 bp_cache_delete( $group_id, 'bp_group_admins' ); 185 185 } 186 186 add_action( 'groups_promote_member', 'groups_clear_group_administrator_cache' ); 187 187 add_action( 'groups_demote_member', 'groups_clear_group_administrator_cache' ); -
src/bp-groups/bp-groups-classes.php
186 186 $bp = buddypress(); 187 187 188 188 // Check cache for group data 189 $group = wp_cache_get( $this->id, 'bp_groups' );189 $group = bp_cache_get( $this->id, 'bp_groups' ); 190 190 191 191 // Cache missed, so query the DB 192 192 if ( false === $group ) { 193 193 $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ); 194 194 195 wp_cache_set( $this->id, $group, 'bp_groups' );195 bp_cache_set( $this->id, $group, 'bp_groups' ); 196 196 } 197 197 198 198 // No group found so set the ID and bail … … 344 344 345 345 do_action_ref_array( 'groups_group_after_save', array( &$this ) ); 346 346 347 wp_cache_delete( $this->id, 'bp_groups' );347 bp_cache_delete( $this->id, 'bp_groups' ); 348 348 349 349 return true; 350 350 } … … 372 372 373 373 do_action_ref_array( 'bp_groups_delete_group', array( &$this, $user_ids ) ); 374 374 375 wp_cache_delete( $this->id, 'bp_groups' );375 bp_cache_delete( $this->id, 'bp_groups' ); 376 376 377 377 // Finally remove the group entry from the DB 378 378 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name} WHERE id = %d", $this->id ) ) ) … … 2422 2422 2423 2423 $bp = buddypress(); 2424 2424 2425 $count = wp_cache_get( $user_id, 'bp_group_invite_count' );2425 $count = bp_cache_get( $user_id, 'bp_group_invite_count' ); 2426 2426 2427 2427 if ( false === $count ) { 2428 2428 $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d", $user_id ) ); 2429 wp_cache_set( $user_id, $count, 'bp_group_invite_count' );2429 bp_cache_set( $user_id, $count, 'bp_group_invite_count' ); 2430 2430 } 2431 2431 2432 2432 return $count; … … 2630 2630 public static function get_group_administrator_ids( $group_id ) { 2631 2631 global $bp, $wpdb; 2632 2632 2633 $group_admins = wp_cache_get( $group_id, 'bp_group_admins' );2633 $group_admins = bp_cache_get( $group_id, 'bp_group_admins' ); 2634 2634 2635 2635 if ( false === $group_admins ) { 2636 2636 $group_admins = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) ); 2637 2637 2638 wp_cache_set( $group_id, $group_admins, 'bp_group_admins' );2638 bp_cache_set( $group_id, $group_admins, 'bp_group_admins' ); 2639 2639 } 2640 2640 2641 2641 return $group_admins; -
src/bp-groups/bp-groups-functions.php
644 644 * @return int 645 645 */ 646 646 function groups_get_total_group_count() { 647 $count = wp_cache_get( 'bp_total_group_count', 'bp' );647 $count = bp_cache_get( 'bp_total_group_count', 'bp' ); 648 648 649 649 if ( false === $count ) { 650 650 $count = BP_Groups_Group::get_total_group_count(); 651 wp_cache_set( 'bp_total_group_count', $count, 'bp' );651 bp_cache_set( 'bp_total_group_count', $count, 'bp' ); 652 652 } 653 653 654 654 return $count; … … 686 686 if ( empty( $user_id ) ) 687 687 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 688 688 689 $count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' );689 $count = bp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' ); 690 690 691 691 if ( false === $count ) { 692 692 $count = BP_Groups_Member::total_group_count( $user_id ); 693 wp_cache_set( 'bp_total_groups_for_user_' . $user_id, $count, 'bp' );693 bp_cache_set( 'bp_total_groups_for_user_' . $user_id, $count, 'bp' ); 694 694 } 695 695 696 696 return $count; -
src/bp-groups/bp-groups-loader.php
676 676 677 677 parent::setup_title(); 678 678 } 679 680 /** 681 * Setup cache groups 682 * 683 * @since BuddyPress (2.2.0) 684 */ 685 public function setup_cache_groups() { 686 687 // Global groups 688 wp_cache_add_global_groups( array( 689 'bp_groups', 690 'bp_group_admins', 691 'bp_group_invite_count' 692 ) ); 693 694 parent::setup_cache_groups(); 695 } 679 696 } 680 697 681 698 /** -
src/bp-members/bp-members-cache.php
22 22 23 23 $cached_member_ids = array(); 24 24 foreach ( $member_types as $member_type ) { 25 wp_cache_set( $member_type->object_id, $member_type->name, 'bp_member_type' );25 bp_cache_set( $member_type->object_id, $member_type->name, 'bp_member_type' ); 26 26 $cached_member_ids[] = $member_type->object_id; 27 27 } 28 28 29 29 // Cache an empty value for users with no type. 30 30 foreach ( array_diff( $uncached_member_ids, $cached_member_ids ) as $no_type_id ) { 31 wp_cache_set( $no_type_id, '', 'bp_member_type' );31 bp_cache_set( $no_type_id, '', 'bp_member_type' ); 32 32 } 33 33 } 34 34 add_action( 'bp_user_query_populate_extras', 'bp_members_prefetch_member_type' ); … … 43 43 * @param int $user_id ID of the deleted user. 44 44 */ 45 45 function bp_members_clear_member_type_cache( $user_id ) { 46 wp_cache_delete( $user_id, 'bp_member_type' );46 bp_cache_delete( $user_id, 'bp_member_type' ); 47 47 } 48 48 add_action( 'wpmu_delete_user', 'bp_members_clear_member_type_cache' ); 49 49 add_action( 'delete_user', 'bp_members_clear_member_type_cache' ); -
src/bp-members/bp-members-functions.php
200 200 return false; 201 201 } 202 202 203 if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {203 if ( !$userdata = bp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) { 204 204 $userdata = BP_Core_User::get_core_userdata( $user_id ); 205 wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );205 bp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' ); 206 206 } 207 207 208 208 /** … … 296 296 $bp = buddypress(); 297 297 298 298 // Check cache for user nicename 299 $username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' );299 $username = bp_cache_get( 'bp_user_username_' . $user_id, 'bp' ); 300 300 if ( false === $username ) { 301 301 302 302 // Cache not found so prepare to update it … … 345 345 346 346 // Add this to cache 347 347 if ( ( true === $update_cache ) && !empty( $username ) ) { 348 wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );348 bp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' ); 349 349 350 350 // @todo bust this cache if no $username found? 351 351 //} else { 352 // wp_cache_delete( 'bp_user_username_' . $user_id );352 // bp_cache_delete( 'bp_user_username_' . $user_id ); 353 353 } 354 354 355 355 /** … … 378 378 function bp_members_get_user_nicename( $user_id ) { 379 379 $bp = buddypress(); 380 380 381 if ( !$user_nicename = wp_cache_get( 'bp_members_user_nicename_' . $user_id, 'bp' ) ) {381 if ( !$user_nicename = bp_cache_get( 'bp_members_user_nicename_' . $user_id, 'bp' ) ) { 382 382 $update_cache = true; 383 383 384 384 // User ID matches logged in user … … 413 413 414 414 // Add this to cache 415 415 if ( true == $update_cache && !empty( $user_nicename ) ) { 416 wp_cache_set( 'bp_members_user_nicename_' . $user_id, $user_nicename, 'bp' );416 bp_cache_set( 'bp_members_user_nicename_' . $user_id, $user_nicename, 'bp' ); 417 417 } 418 418 419 419 /** … … 435 435 */ 436 436 function bp_core_get_user_email( $uid ) { 437 437 438 if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {438 if ( !$email = bp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) { 439 439 440 440 // User exists 441 441 $ud = bp_core_get_core_userdata( $uid ); … … 447 447 $email = ''; 448 448 } 449 449 450 wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );450 bp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' ); 451 451 } 452 452 453 453 /** … … 529 529 530 530 $uncached_ids = array(); 531 531 foreach ( $user_ids as $user_id ) { 532 if ( false === wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {532 if ( false === bp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) { 533 533 $uncached_ids[] = $user_id; 534 534 } 535 535 } … … 576 576 } 577 577 578 578 foreach ( $fullnames as $fuser_id => $fname ) { 579 wp_cache_set( 'bp_user_fullname_' . $fuser_id, $fname, 'bp' );579 bp_cache_set( 'bp_user_fullname_' . $fuser_id, $fname, 'bp' ); 580 580 } 581 581 } 582 582 583 583 $retval = array(); 584 584 foreach ( $user_ids as $user_id ) { 585 $retval[ $user_id ] = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' );585 $retval[ $user_id ] = bp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ); 586 586 } 587 587 588 588 return $retval; … … 691 691 function bp_core_get_total_member_count() { 692 692 global $wpdb; 693 693 694 $count = wp_cache_get( 'bp_total_member_count', 'bp' );694 $count = bp_cache_get( 'bp_total_member_count', 'bp' ); 695 695 696 696 if ( false === $count ) { 697 697 $status_sql = bp_core_get_status_sql(); 698 698 $count = $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->users} WHERE {$status_sql}" ); 699 wp_cache_set( 'bp_total_member_count', $count, 'bp' );699 bp_cache_set( 'bp_total_member_count', $count, 'bp' ); 700 700 } 701 701 702 702 /** … … 2592 2592 2593 2593 // Bust the cache if the type has been updated. 2594 2594 if ( ! is_wp_error( $retval ) ) { 2595 wp_cache_delete( $user_id, 'bp_member_type' );2595 bp_cache_delete( $user_id, 'bp_member_type' ); 2596 2596 2597 2597 /** 2598 2598 * Fires just after a user's member type has been changed. … … 2621 2621 * types (if $single is false). Returns false on failure. 2622 2622 */ 2623 2623 function bp_get_member_type( $user_id, $single = true ) { 2624 $types = wp_cache_get( $user_id, 'bp_member_type' );2624 $types = bp_cache_get( $user_id, 'bp_member_type' ); 2625 2625 2626 2626 if ( false === $types ) { 2627 2627 $types = bp_get_object_terms( $user_id, 'bp_member_type' ); 2628 2628 2629 2629 if ( ! is_wp_error( $types ) ) { 2630 2630 $types = wp_list_pluck( $types, 'name' ); 2631 wp_cache_set( $user_id, $types, 'bp_member_type' );2631 bp_cache_set( $user_id, $types, 'bp_member_type' ); 2632 2632 } 2633 2633 } 2634 2634 -
src/bp-members/bp-members-loader.php
276 276 277 277 parent::setup_title(); 278 278 } 279 280 /** 281 * Setup cache groups 282 * 283 * @since BuddyPress (2.2.0) 284 */ 285 public function setup_cache_groups() { 286 287 // Global groups 288 wp_cache_add_global_groups( array( 289 'bp_member_type' 290 ) ); 291 292 parent::setup_cache_groups(); 293 } 279 294 } 280 295 281 296 /** -
src/bp-messages/bp-messages-cache.php
54 54 */ 55 55 function bp_messages_clear_unread_count_cache_on_message_save( BP_Messages_Message $message ) { 56 56 foreach ( (array) $message->recipients as $recipient ) { 57 wp_cache_delete( $recipient->user_id, 'bp_messages_unread_count' );57 bp_cache_delete( $recipient->user_id, 'bp_messages_unread_count' ); 58 58 } 59 59 } 60 60 add_action( 'messages_message_after_save', 'bp_messages_clear_unread_count_cache_on_message_save' ); … … 68 68 * array of thread IDs 69 69 */ 70 70 function bp_messages_clear_unread_count_cache_on_message_delete( $thread_ids ) { 71 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );71 bp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 72 72 } 73 73 add_action( 'messages_before_delete_thread', 'bp_messages_clear_unread_count_cache_on_message_delete' ); 74 74 … … 80 80 * @since BuddyPress (2.0.0) 81 81 */ 82 82 function bp_notices_clear_cache( $notice ) { 83 wp_cache_delete( 'active_notice', 'bp_messages' );83 bp_cache_delete( 'active_notice', 'bp_messages' ); 84 84 } 85 85 add_action( 'messages_notice_after_save', 'bp_notices_clear_cache' ); 86 86 add_action( 'messages_notice_before_delete', 'bp_notices_clear_cache' ); -
src/bp-messages/bp-messages-classes.php
434 434 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ); 435 435 $wpdb->query($sql); 436 436 437 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );437 bp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 438 438 } 439 439 440 440 /** … … 450 450 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ); 451 451 $wpdb->query($sql); 452 452 453 wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );453 bp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); 454 454 } 455 455 456 456 /** … … 533 533 $user_id = bp_loggedin_user_id(); 534 534 } 535 535 536 $unread_count = wp_cache_get( $user_id, 'bp_messages_unread_count' );536 $unread_count = bp_cache_get( $user_id, 'bp_messages_unread_count' ); 537 537 538 538 if ( false === $unread_count ) { 539 539 $unread_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM(unread_count) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 AND sender_only = 0", $user_id ) ); 540 540 541 wp_cache_set( $user_id, $unread_count, 'bp_messages_unread_count' );541 bp_cache_set( $user_id, $unread_count, 'bp_messages_unread_count' ); 542 542 } 543 543 544 544 /** … … 1132 1132 * @return object The BP_Messages_Notice object 1133 1133 */ 1134 1134 public static function get_active() { 1135 $notice = wp_cache_get( 'active_notice', 'bp_messages' );1135 $notice = bp_cache_get( 'active_notice', 'bp_messages' ); 1136 1136 1137 1137 if ( false === $notice ) { 1138 1138 global $wpdb, $bp; … … 1140 1140 $notice_id = $wpdb->get_var( "SELECT id FROM {$bp->messages->table_name_notices} WHERE is_active = 1" ); 1141 1141 $notice = new BP_Messages_Notice( $notice_id ); 1142 1142 1143 wp_cache_set( 'active_notice', $notice, 'bp_messages' );1143 bp_cache_set( 'active_notice', $notice, 'bp_messages' ); 1144 1144 } 1145 1145 1146 1146 return $notice; -
src/bp-messages/bp-messages-loader.php
292 292 293 293 parent::setup_title(); 294 294 } 295 296 /** 297 * Setup cache groups 298 * 299 * @since BuddyPress (2.2.0) 300 */ 301 public function setup_cache_groups() { 302 303 // Global groups 304 wp_cache_add_global_groups( array( 305 'bp_messages', 306 'bp_messages_unread_count', 307 'message_meta' 308 ) ); 309 310 parent::setup_cache_groups(); 311 } 295 312 } 296 313 297 314 /** -
src/bp-notifications/bp-notifications-cache.php
14 14 * @param BP_Notification_Notification $n Notification object. 15 15 */ 16 16 function bp_notifications_clear_all_for_user_cache_after_save( BP_Notifications_Notification $n ) { 17 wp_cache_delete( 'all_for_user_' . $n->user_id, 'bp_notifications' );17 bp_cache_delete( 'all_for_user_' . $n->user_id, 'bp_notifications' ); 18 18 } 19 19 add_action( 'bp_notification_after_save', 'bp_notifications_clear_all_for_user_cache_after_save' ); 20 20 … … 35 35 } 36 36 37 37 foreach ( array_unique( $user_ids ) as $user_id ) { 38 wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' );38 bp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' ); 39 39 } 40 40 } 41 41 add_action( 'bp_notification_before_delete', 'bp_notifications_clear_all_for_user_cache_before_delete' ); -
src/bp-notifications/bp-notifications-classes.php
681 681 682 682 // make sure we delete the notification cache for the user on update 683 683 if ( ! empty( $where_args['user_id'] ) ) { 684 wp_cache_delete( 'all_for_user_' . $where_args['user_id'], 'bp_notifications' );684 bp_cache_delete( 'all_for_user_' . $where_args['user_id'], 'bp_notifications' ); 685 685 } 686 686 687 687 return self::_update( $update['data'], $where['data'], $update['format'], $where['format'] ); -
src/bp-notifications/bp-notifications-functions.php
143 143 } 144 144 145 145 // Get notifications out of the cache, or query if necessary 146 $notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' );146 $notifications = bp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' ); 147 147 if ( false === $notifications ) { 148 148 $notifications = BP_Notifications_Notification::get( array( 149 149 'user_id' => $user_id 150 150 ) ); 151 wp_cache_set( 'all_for_user_' . $user_id, $notifications, 'bp_notifications' );151 bp_cache_set( 'all_for_user_' . $user_id, $notifications, 'bp_notifications' ); 152 152 } 153 153 154 154 // Filter and return -
src/bp-notifications/bp-notifications-loader.php
237 237 238 238 parent::setup_title(); 239 239 } 240 241 /** 242 * Setup cache groups 243 * 244 * @since BuddyPress (2.2.0) 245 */ 246 public function setup_cache_groups() { 247 248 // Global groups 249 wp_cache_add_global_groups( array( 250 'bp_notifications' 251 ) ); 252 253 parent::setup_cache_groups(); 254 } 240 255 } 241 256 242 257 /** -
src/bp-xprofile/bp-xprofile-cache.php
13 13 if ( !defined( 'ABSPATH' ) ) exit; 14 14 15 15 /** 16 * Determine which xprofile fields do not have cached values for a user. 17 * 18 * @since BuddyPress (2.2.0) 19 * 20 * @param int $user_id User ID to check 21 * @param array $field_ids XProfile field IDs. 22 * @return array 23 */ 24 function bp_xprofile_get_non_cached_field_ids( $user_id = 0, $field_ids = array() ) { 25 $uncached_fields = array(); 26 27 foreach ( $field_ids as $field_id ) { 28 $field_id = (int) $field_id; 29 $cache_key = "{$user_id}:{$field_id}"; 30 if ( false === wp_cache_get( $cache_key, 'bp_xprofile_data' ) ) { 31 $uncached_fields[] = $field_id; 32 } 33 } 34 35 return $uncached_fields; 36 } 37 38 /** 16 39 * Slurp up xprofilemeta for a specified set of profile objects. 17 40 * 18 41 * We do not use bp_update_meta_cache() for the xprofile component. This is … … 112 135 foreach ( $cache as $object_type => $object_caches ) { 113 136 $cache_group = $cache_groups[ $object_type ]; 114 137 foreach ( $object_caches as $object_id => $object_cache ) { 115 wp_cache_set( $object_id, $object_cache, $cache_group );138 bp_cache_set( $object_id, $object_cache, $cache_group ); 116 139 } 117 140 } 118 141 } … … 121 144 } 122 145 123 146 function xprofile_clear_profile_groups_object_cache( $group_obj ) { 124 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );125 wp_cache_delete( 'xprofile_group_' . $group_obj->id, 'bp' );147 bp_cache_delete( 'xprofile_groups_inc_empty', 'bp' ); 148 bp_cache_delete( 'xprofile_group_' . $group_obj->id, 'bp' ); 126 149 } 127 150 add_action( 'xprofile_group_after_delete', 'xprofile_clear_profile_groups_object_cache' ); 128 151 add_action( 'xprofile_group_after_save', 'xprofile_clear_profile_groups_object_cache' ); 129 152 130 153 function xprofile_clear_profile_data_object_cache( $group_id ) { 131 wp_cache_delete( 'bp_user_fullname_' . bp_loggedin_user_id(), 'bp' );154 bp_cache_delete( 'bp_user_fullname_' . bp_loggedin_user_id(), 'bp' ); 132 155 } 133 156 add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' ); 134 157 … … 142 165 */ 143 166 function xprofile_clear_fullname_cache_on_profile_field_edit( $data ) { 144 167 if ( 1 == $data->field_id ) { 145 wp_cache_delete( 'bp_user_fullname_' . $data->user_id, 'bp' );168 bp_cache_delete( 'bp_user_fullname_' . $data->user_id, 'bp' ); 146 169 } 147 170 } 148 171 add_action( 'xprofile_data_after_save', 'xprofile_clear_fullname_cache_on_profile_field_edit' ); … … 156 179 */ 157 180 function xprofile_clear_profile_field_object_cache( $field_obj ) { 158 181 // Clear default visibility level cache 159 wp_cache_delete( 'xprofile_default_visibility_levels', 'bp' );182 bp_cache_delete( 'xprofile_default_visibility_levels', 'bp' ); 160 183 161 184 // Modified fields can alter parent group status, in particular when 162 185 // the group goes from empty to non-empty. Bust its cache, as well as 163 186 // the global group_inc_empty cache 164 wp_cache_delete( 'xprofile_group_' . $field_obj->group_id, 'bp' );165 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );187 bp_cache_delete( 'xprofile_group_' . $field_obj->group_id, 'bp' ); 188 bp_cache_delete( 'xprofile_groups_inc_empty', 'bp' ); 166 189 } 167 190 add_action( 'xprofile_fields_saved_field', 'xprofile_clear_profile_field_object_cache' ); 168 191 add_action( 'xprofile_fields_deleted_field', 'xprofile_clear_profile_field_object_cache' ); … … 175 198 * @param BP_XProfile_ProfileData $data_obj 176 199 */ 177 200 function xprofile_clear_profiledata_object_cache( $data_obj ) { 178 wp_cache_delete( $data_obj->field_id, 'bp_xprofile_data_' . $data_obj->user_id );201 bp_cache_delete( $data_obj->field_id, 'bp_xprofile_data_' . $data_obj->user_id ); 179 202 } 180 203 add_action( 'xprofile_data_after_save', 'xprofile_clear_profiledata_object_cache' ); 181 204 add_action( 'xprofile_data_after_delete', 'xprofile_clear_profiledata_object_cache' ); … … 196 219 * @since BuddyPress (2.0.0) 197 220 */ 198 221 function xprofile_clear_fullname_field_id_cache() { 199 wp_cache_delete( 'fullname_field_id', 'bp_xprofile' );222 bp_cache_delete( 'fullname_field_id', 'bp_xprofile' ); 200 223 } 201 224 add_action( 'update_option_bp-xprofile-fullname-field-name', 'xprofile_clear_fullname_field_id_cache' ); 202 225 -
src/bp-xprofile/bp-xprofile-classes.php
26 26 public function populate( $id ) { 27 27 global $wpdb, $bp; 28 28 29 $group = wp_cache_get( 'xprofile_group_' . $this->id, 'bp' );29 $group = bp_cache_get( 'xprofile_group_' . $this->id, 'bp' ); 30 30 31 31 if ( false === $group ) { 32 32 $group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) ); … … 367 367 foreach ( $group_ids as $group_id ) { 368 368 369 369 // If cached data is found, use it 370 if ( $group_data = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {370 if ( $group_data = bp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { 371 371 $groups[ $group_id ] = $group_data; 372 372 373 373 // Otherwise leave a placeholder so we don't lose the order … … 392 392 // and add it to the cache 393 393 foreach ( (array) $queried_gdata as $gdata ) { 394 394 $groups[ $gdata->id ] = $gdata; 395 wp_cache_set( 'xprofile_group_' . $gdata->id, $gdata, 'bp' );395 bp_cache_set( 'xprofile_group_' . $gdata->id, $gdata, 'bp' ); 396 396 } 397 397 } 398 398 … … 422 422 } 423 423 424 424 // purge profile field group cache 425 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );425 bp_cache_delete( 'xprofile_groups_inc_empty', 'bp' ); 426 426 427 427 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) ); 428 428 } … … 482 482 public static function fetch_default_visibility_levels() { 483 483 global $wpdb, $bp; 484 484 485 $default_visibility_levels = wp_cache_get( 'xprofile_default_visibility_levels', 'bp' );485 $default_visibility_levels = bp_cache_get( 'xprofile_default_visibility_levels', 'bp' ); 486 486 487 487 if ( false === $default_visibility_levels ) { 488 488 $levels = $wpdb->get_results( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" ); … … 497 497 } 498 498 } 499 499 500 wp_cache_set( 'xprofile_default_visibility_levels', $default_visibility_levels, 'bp' );500 bp_cache_set( 'xprofile_default_visibility_levels', $default_visibility_levels, 'bp' ); 501 501 } 502 502 503 503 return $default_visibility_levels; … … 1222 1222 public function populate( $field_id, $user_id ) { 1223 1223 global $wpdb, $bp; 1224 1224 1225 $cache_ group = 'bp_xprofile_data_' . $user_id;1226 $profiledata = wp_cache_get( $field_id, $cache_group);1225 $cache_key = "{$user_id}:{$field_id}"; 1226 $profiledata = bp_cache_get( $cache_key, 'bp_xprofile_data' ); 1227 1227 1228 1228 if ( false === $profiledata ) { 1229 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );1229 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ); 1230 1230 $profiledata = $wpdb->get_row( $sql ); 1231 1231 1232 1232 if ( $profiledata ) { 1233 wp_cache_set( $field_id, $profiledata, $cache_group);1233 bp_cache_set( $cache_key, $profiledata, 'bp_xprofile_data' ); 1234 1234 } 1235 1235 } 1236 1236 … … 1259 1259 global $wpdb, $bp; 1260 1260 1261 1261 // Check cache first 1262 $cached = wp_cache_get( $this->field_id, 'bp_xprofile_data_' . $this->user_id ); 1262 $cache_key = "{$this->user_id}:{$this->field_id}"; 1263 $cached = bp_cache_get( $cache_key, 'bp_xprofile_data' ); 1263 1264 1264 1265 if ( $cached && ! empty( $cached->id ) ) { 1265 1266 $retval = true; … … 1400 1401 1401 1402 $data = array(); 1402 1403 1403 $ cache_group = 'bp_xprofile_data_' . $user_id;1404 $uncached_field_ids = bp_xprofile_get_non_cached_field_ids( $user_id, $field_ids, 'bp_xprofile_data' ); 1404 1405 1405 $uncached_field_ids = bp_get_non_cached_ids( $field_ids, $cache_group );1406 1407 1406 // Prime the cache 1408 1407 if ( ! empty( $uncached_field_ids ) ) { 1409 1408 $bp = buddypress(); … … 1426 1425 // Set caches 1427 1426 foreach ( $uncached_field_ids as $field_id ) { 1428 1427 1428 $cache_key = "{$user_id}:{$field_id}"; 1429 1429 1430 // If a value was found, cache it 1430 1431 if ( isset( $queried_data[ $field_id ] ) ) { 1431 wp_cache_set( $field_id, $queried_data[ $field_id ], $cache_group);1432 bp_cache_set( $cache_key, $queried_data[ $field_id ], 'bp_xprofile_data' ); 1432 1433 1433 1434 // If no value was found, cache an empty item 1434 1435 // to avoid future cache misses … … 1440 1441 $d->value = ''; 1441 1442 $d->last_updated = ''; 1442 1443 1443 wp_cache_set( $field_id, $d, $cache_group);1444 bp_cache_set( $cache_key, $d, 'bp_xprofile_data' ); 1444 1445 } 1445 1446 } 1446 1447 } 1447 1448 1448 1449 // Now that all items are cached, fetch them 1449 1450 foreach ( $field_ids as $field_id ) { 1450 $data[] = wp_cache_get( $field_id, $cache_group ); 1451 $cache_key = "{$user_id}:{$field_id}"; 1452 $data[] = bp_cache_get( $cache_key, 'bp_xprofile_data' ); 1451 1453 } 1452 1454 1453 1455 return $data; … … 1460 1462 * @return array 1461 1463 */ 1462 1464 public static function get_all_for_user( $user_id ) { 1463 global $wpdb, $bp;1464 1465 1465 1466 $groups = bp_xprofile_get_groups( array( 1466 1467 'user_id' => $user_id, … … 1514 1515 } else { 1515 1516 1516 1517 // Check cache first 1517 $fielddata = wp_cache_get( $field_id, 'bp_xprofile_data_' . $user_id ); 1518 $cache_key = "{$user_id}:{$field_id}"; 1519 $fielddata = bp_cache_get( $cache_key, 'bp_xprofile_data' ); 1518 1520 if ( false === $fielddata || empty( $fielddata->id ) ) { 1519 1521 $fielddata_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ) ); 1520 1522 } else { … … 1551 1553 // Assemble uncached IDs 1552 1554 $uncached_ids = array(); 1553 1555 foreach ( $user_ids as $user_id ) { 1554 if ( false === wp_cache_get( $field_id, 'bp_xprofile_data_' . $user_id ) ) { 1556 $cache_key = "{$user_id}:{$field_id}"; 1557 if ( false === bp_cache_get( $cache_key, 'bp_xprofile_data' ) ) { 1555 1558 $uncached_ids[] = $user_id; 1556 1559 } 1557 1560 } … … 1583 1586 $d->last_updated = ''; 1584 1587 } 1585 1588 1586 wp_cache_set( $field_id, $d, 'bp_xprofile_data_' . $d->user_id ); 1589 $cache_key = "{$d->user_id}:{$field_id}"; 1590 bp_cache_set( $field_id, $d, 'bp_xprofile_data' ); 1587 1591 } 1588 1592 } 1589 1593 1590 1594 // Now that the cache is primed with all data, fetch it 1591 1595 $data = array(); 1592 1596 foreach ( $user_ids as $user_id ) { 1593 $data[] = wp_cache_get( $field_id, 'bp_xprofile_data_' . $user_id ); 1597 $cache_key = "{$user_id}:{$field_id}"; 1598 $data[] = bp_cache_get( $cache_key, 'bp_xprofile_data' ); 1594 1599 } 1595 1600 1596 1601 // If a single ID was passed, just return the value -
src/bp-xprofile/bp-xprofile-functions.php
981 981 * @return int Field ID. 982 982 */ 983 983 function bp_xprofile_fullname_field_id() { 984 $id = wp_cache_get( 'fullname_field_id', 'bp_xprofile' );984 $id = bp_cache_get( 'fullname_field_id', 'bp_xprofile' ); 985 985 986 986 if ( false === $id ) { 987 987 global $wpdb; … … 989 989 $bp = buddypress(); 990 990 $id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", bp_xprofile_fullname_field_name() ) ); 991 991 992 wp_cache_set( 'fullname_field_id', $id, 'bp_xprofile' );992 bp_cache_set( 'fullname_field_id', $id, 'bp_xprofile' ); 993 993 } 994 994 995 995 return absint( $id ); -
src/bp-xprofile/bp-xprofile-loader.php
353 353 } 354 354 355 355 /** 356 * Setup cache groups 357 * 358 * @since BuddyPress (2.2.0) 359 */ 360 public function setup_cache_groups() { 361 362 // Global groups 363 wp_cache_add_global_groups( array( 364 'bp_xprofile', 365 'bp_xprofile_data', 366 'xprofile_meta' 367 ) ); 368 369 parent::setup_cache_groups(); 370 } 371 372 /** 356 373 * Adds "Settings > Profile" subnav item under the "Settings" adminbar menu. 357 374 * 358 375 * @since BuddyPress (2.0.0) -
src/bp-xprofile/bp-xprofile-template.php
801 801 * @return object $groups 802 802 */ 803 803 function bp_profile_get_field_groups() { 804 $groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' );804 $groups = bp_cache_get( 'xprofile_groups_inc_empty', 'bp' ); 805 805 806 806 if ( empty( $groups ) ) { 807 807 $groups = bp_xprofile_get_groups( array( 'fetch_fields' => true ) ); 808 wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' );808 bp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' ); 809 809 } 810 810 811 811 /** … … 899 899 if ( !is_numeric( $group_id ) ) 900 900 $group_id = 1; 901 901 902 if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {902 if ( !$group = bp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { 903 903 $group = new BP_XProfile_Group($group_id); 904 wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );904 bp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' ); 905 905 } 906 906 907 907 /**