Skip to content

fix: replace GROUP_CONCAT with PHP-side aggregation - #170

Open
i-am-chitti wants to merge 1 commit into
WordPress:mainfrom
i-am-chitti:issue-133
Open

fix: replace GROUP_CONCAT with PHP-side aggregation#170
i-am-chitti wants to merge 1 commit into
WordPress:mainfrom
i-am-chitti:issue-133

Conversation

@i-am-chitti

Copy link
Copy Markdown
Contributor

Description

Currently, wp_get_presence_summary() and wp_get_active_rooms() both temporarily modify the MySQL session variable group_concat_max_len before performing queries with GROUP_CONCAT.

This pattern has several issues:

  1. It does not work reliably in environments that pool/proxy database connections (e.g., ProxySQL, PlanetScale) because the mutated session state is not guaranteed to persist across a connection checkout.
  2. In some managed environments, the database user lacks privileges to modify session variables using SET SESSION.
  3. It makes the codebase dependent on MySQL-specific session operations.

Since the active presence table is small and transient, fetching the raw room and user_id rows 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.php
    • Removed the SET SESSION group_concat_max_len queries from both wp_get_presence_summary() and wp_get_active_rooms().
    • Updated wp_get_presence_summary() to fetch raw room and user_id columns and aggregate counts/users per prefix in PHP.
    • Updated 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 test

Verify 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.

@i-am-chitti
i-am-chitti requested a review from josephfusco as a code owner July 30, 2026 19:36
@github-actions

Copy link
Copy Markdown
Contributor

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props iamchitti.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown
Contributor

▶ Preview in WordPress Playground

Open in WordPress Playground

Boots 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 256811818bdcc37b051440ca4536fe73924892b2. Auto-updates when you push.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 28.87%. Comparing base (3a2ae99) to head (2568118).
⚠️ Report is 26 commits behind head on main.

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              
Flag Coverage Δ
phpunit 28.87% <100.00%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@josephfusco josephfusco added [Type] Bug An existing feature is broken [Area] Database Issues for the wp_presence table and cron cleanup labels Jul 31, 2026
@josephfusco josephfusco changed the title Database: Replace GROUP_CONCAT with PHP-side aggregation in presence fix: replace GROUP_CONCAT with PHP-side aggregation Jul 31, 2026
@josephfusco josephfusco added the Performance Work relates to query load, cache behavior, or scaling label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Database Issues for the wp_presence table and cron cleanup Performance Work relates to query load, cache behavior, or scaling [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants