PROD-9998: cache xProfile visibility check, cap ReadyLaunch dropdown - #5047
Open
rezwan-buddyboss wants to merge 1 commit into
Open
PROD-9998: cache xProfile visibility check, cap ReadyLaunch dropdown#5047rezwan-buddyboss wants to merge 1 commit into
rezwan-buddyboss wants to merge 1 commit into
Conversation
… dropdown BB_XProfile_Visibility::user_data_exists() bypassed the object cache, using only a per-request static array before hitting the DB directly. On a persistent-cache (Redis) site this meant the same user's visibility-scan result was recomputed from scratch every request. Add the same wp_cache_get()/wp_cache_set( ..., 'bp_xprofile' ) pattern already used by the sibling is_valid_field() method, with invalidation wired into every write path that can change a user's visibility-data existence (save(), delete(), delete_specific_data_for_user(), delete_for_field()) since no after_save/after_delete cache-invalidation hook previously existed. Also applies the theme fix's recipient-count cap (see companion PR) to the Platform's own ReadyLaunch copy of the header messages dropdown template, which has the identical loop structure. Companion fix: buddyboss/buddyboss-theme#2817
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PROD link: https://buddyboss.atlassian.net/browse/PROD-9998
Issue
Same underlying ticket as buddyboss/buddyboss-theme#2817: on a large site with a message thread that has a large recipient list, resolving each recipient's display name for the header's unread-messages dropdown triggers one xProfile visibility check per recipient. This PR addresses two things the theme-side fix alone doesn't cover:
BB_XProfile_Visibility::user_data_exists()never used the persistent object cache at all, and the Platform ships its own separate copy of the same dropdown template for ReadyLaunch that has the identical unbounded-loop problem.Root cause
BB_XProfile_Visibility::user_data_exists()only cached its result in a per-requeststatic $cachearray, then fell straight through to$wpdb->get_var()on every cache miss. It never calledwp_cache_get()/wp_cache_set(), so on a site running Redis or Memcached, the same user's visibility-scan result was recomputed from the database on every single page load instead of being reused across requests — the persistent cache layer existed for the rest of xProfile (the sibling methodis_valid_field()in this same class already uses the standardwp_cache_get()/wp_cache_set( ..., 'bp_xprofile' )pattern) but was simply missing here.Separately,
src/bp-templates/bp-nouveau/readylaunch/header/unread-messages.php— the Platform's own template for sites using the ReadyLaunch header instead of the classic BuddyBoss Theme header — has the exact same recipient-loop structure as the theme'stemplate-parts/unread-messages.php, so it has the exact same per-recipient-resolution problem the theme PR fixes.Fix
Object cache for
user_data_exists(): added awp_cache_get( $cache_key, 'bp_xprofile' )check before the DB query, andwp_cache_set()after computing the result, mirroringis_valid_field()'s existing pattern. Added a newdelete_user_data_exists_cache( $user_id )helper and called it from every write path that can change a user's visibility-data existence:save(),delete(), anddelete_specific_data_for_user().delete_for_field()needed an extra step — it does a bulk$wpdb->query()across every user with data on a given field without going throughsave()/delete(), so no invalidation hook fires for the individual users affected. Fixed by first querying the affecteduser_ids (SELECT DISTINCT user_id ... WHERE field_id = %d) before the delete, then invalidating each one's cache afterward.Note: this cache addition has no visible effect on a single page-load's query count — Query Monitor won't show a difference from it alone. It only matters on a site with a persistent cache backend, where it's the difference between "resolved once per cache lifetime" and "resolved fresh on every request." The query-count fix that actually shows up in Query Monitor is the theme-side loop cap in the companion PR.
ReadyLaunch template: applied the identical recipient-count cap as the theme PR — resolve
$recipient_dataonly for the logged-in user or one of the first 3 "other" recipients, track the true total via$other_recipient_total, and switch every othercount( $other_recipients )read in the file to that counter — tosrc/bp-templates/bp-nouveau/readylaunch/header/unread-messages.php, since it's structurally identical to the file the theme PR fixes.