fix: replace GROUP_CONCAT with PHP-side aggregation - #170
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
▶ Preview in WordPress PlaygroundBoots a fresh WordPress with this PR's presence-api build, seeds 5 demo users, and drops you on the dashboard. Stress-test variant: 40 demo users · Built from |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #170 +/- ##
============================================
+ Coverage 28.56% 28.87% +0.31%
Complexity 161 161
============================================
Files 15 15
Lines 1817 1825 +8
============================================
+ Hits 519 527 +8
Misses 1298 1298
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Currently,
wp_get_presence_summary()andwp_get_active_rooms()both temporarily modify the MySQL session variablegroup_concat_max_lenbefore performing queries withGROUP_CONCAT.This pattern has several issues:
SET SESSION.Since the active presence table is small and transient, fetching the raw
roomanduser_idrows and performing the aggregation in PHP is a highly reliable and performant alternative.This PR implements PHP-side aggregation for:
wp_get_presence_summary()wp_get_active_rooms()Fixes
Proposed Changes
includes/functions.phpSET SESSION group_concat_max_lenqueries from bothwp_get_presence_summary()andwp_get_active_rooms().wp_get_presence_summary()to fetch rawroomanduser_idcolumns and aggregate counts/users per prefix in PHP.wp_get_active_rooms()to fetch raw rows, aggregate user lists per room, sort them, and sort the active rooms list by total entry counts descending in PHP.How to Test / Verification
Run the PHPUnit test suite:
npm run testVerify that all unit tests pass successfully.
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.5 Flash
Used for: Help with refactor, replace and implementing the equivalent sorting and drafting PR description.