Repository navigation
perf: coalesce presence polling across tabs of the same user - #300
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❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #300 +/- ##
============================================
+ Coverage 78.41% 79.57% +1.16%
Complexity 190 190
============================================
Files 14 14
Lines 2052 2071 +19
============================================
+ Hits 1609 1648 +39
+ Misses 443 423 -20
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
The only concern from review was that the tab-election/relay logic was duplicated across presence-ping.js, active-posts.js, and stale-screen.js, so I pushed a commit extracting it into a shared tab-coordinator.js helper, verified with the existing coalescing e2e tests plus the full PHPUnit/PHPCS/PHPStan suite. |
josephfusco
left a comment
There was a problem hiding this comment.
Thanks for knocking this out, nice work with this!
Fixes #269
Summary
When the same user has an admin screen open in multiple tabs, each tab independently pings Heartbeat, triggering its own
wp_set_presence()write and Who's Online/Active Posts/stale-screen lookup - redundant work that scales with tab count, not with actual viewers.Elects one tab per context (Web Locks) to send the ping; sibling tabs skip their own ping and instead receive the elected tab's response over
BroadcastChannel, so their widgets/banners stay live. Closing the elected tab promotes a sibling automatically. Tabs on a different post or screen are never coalesced with each other.Covers all three tab-scoped ping mechanisms in the plugin:
presence-ping/presence-editor-ping(admin + editor rooms, Who's Online) - dedupe key is screen + post + front-page contextpresence-screen-ping(stale-screen banner) - dedupe key isscreenKeypresence-active-posts-ping(Active Posts widget) - fixed dedupe key, since this ping carries no per-page context (sitewide data). Required first extracting its script from inline PHP into an external file (assets/js/active-posts.js) so it could be enqueued and coalesced like the other two.Also ships
usePresenceUsers, a React hook + coordinator for third-party consumers of the public presence REST endpoint - a related but separate improvement, unaffected by the wp-admin fix above since nothing in this plugin's own UI uses that hook yet.Test plan
presence-poll-coordinator.test.js)npm run test- no regressionsnpm run test:e2e- no regressionsScreenshots
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Assisting with implementation