Skip to content

perf: skip Who's Online payload when room state is unchanged - #288

Merged
josephfusco merged 5 commits into
WordPress:mainfrom
i-am-chitti:perf/268-skip-unchanged-presence-payload
Aug 16, 2026
Merged

perf: skip Who's Online payload when room state is unchanged#288
josephfusco merged 5 commits into
WordPress:mainfrom
i-am-chitti:perf/268-skip-unchanged-presence-payload

Conversation

@i-am-chitti

Copy link
Copy Markdown
Collaborator

Description

Closes #268.

Server hashes the room's meaningful state; the client echoes its last hash. On a match the response carries last-seen timestamps instead of the payload, skipping cache_users(), per-user get_userdata() / get_avatar_url(), label building, and most of the JSON.

Review notes

  • The unchanged reply carries a user_id → last-seen map, not a bare flag: the hash excludes date_gmt (it would flip every tick), so a flag alone breaks the idle dot for backgrounded tabs. Verified the dot still greys at 30s and clears at 60s, matching main.
  • Display names and avatars aren't on the presence row, so profile changes won't reach other widgets until room state changes for another reason.

Testing

  1. Log in as two users - admin in a normal window, an editor in an incognito window - both on the Dashboard. Position the windows side by side so neither covers the other; a fully covered window reports itself hidden and stops pinging, which invalidates the test.
  2. Confirm the editor appears in the admin's Who's Online widget with a solid green dot.
  3. In the admin window, open DevTools → Network and filter admin-ajax (presence rides WordPress's Heartbeat; it has no endpoint of its own). After the first tick, responses should carry presence-online-unchanged with a user_id → last-seen map instead of the full presence-online array, and drop noticeably in size.
  4. In the editor window, switch to a second tab so the Dashboard is backgrounded. Leave it open - closing it deletes the presence entry and tests nothing.
  5. Watch the editor's row in the admin window. The dot should turn grey at ~30s and the row should clear at ~60s - identical to main - while the admin's responses keep coming back as presence-online-unchanged.

Out of scope

heartbeat_received() runs on every admin screen but only the Dashboard consumes the data - off-Dashboard ticks still build an unread payload and can't be hash-suppressed. Will be raising a issue for this.

Measurement

To follow

Screenshots

image image image

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Implementation and tests

@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, joefusco.

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 cf08cff220bba40cd51e83ed0662b9cda8595f36. Auto-updates when you push.

@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.82%. Comparing base (8fdedf8) to head (cf08cff).
⚠️ Report is 39 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #288      +/-   ##
============================================
+ Coverage     75.87%   77.82%   +1.95%     
- Complexity      176      190      +14     
============================================
  Files            14       14              
  Lines          1832     1998     +166     
============================================
+ Hits           1390     1555     +165     
- Misses          442      443       +1     
Flag Coverage Δ
multisite 77.82% <100.00%> (+1.95%) ⬆️
phpunit 76.62% <100.00%> (+2.06%) ⬆️

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

🚀 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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@josephfusco
josephfusco merged commit 555a383 into WordPress:main Aug 16, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip the response body when presence state hasn't changed

2 participants