Skip to content

[WIP] Real-time Collaboration: Cache awareness state to reduce postmeta queries#11067

Open
mindctrl wants to merge 6 commits intoWordPress:trunkfrom
mindctrl:try/post-meta-refactor
Open

[WIP] Real-time Collaboration: Cache awareness state to reduce postmeta queries#11067
mindctrl wants to merge 6 commits intoWordPress:trunkfrom
mindctrl:try/post-meta-refactor

Conversation

@mindctrl
Copy link

@mindctrl mindctrl commented Feb 26, 2026

This is a proof of concept for moving awareness state out of wp_postmeta to cache, using the Transients API, which will use object cache if available and fall back to wp_options if not.

I'm looking for feedback if this is a viable idea in general. If so, I can iterate on this to get it in better shape.

Edit: I branched this off @westonruter PR here: #11002

Trac ticket: https://core.trac.wordpress.org/ticket/64696

Use of AI Tools

I used Claude Opus 4.6 to help with this, mostly for the phpunit test.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

westonruter and others added 4 commits February 22, 2026 20:23
…h_suspended_posts_last_changed_update()

Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…tion in sync storage

Fixes a race condition in `get_updates_after_cursor` where updates inserted during the fetch window could be skipped by the next poll. The method now snapshots `max_meta_id` before fetching to ensure a consistent cursor.

Optimizes `remove_updates_before_cursor` to use a single atomic `DELETE` query instead of the previous read-delete-write approach.

Cleanup now uses direct SQL deletion to bypass `clean_post_cache`. This prevents sync operations from updating the global `posts_last_changed` salt, avoiding site-wide cache invalidation storms during high-frequency editing sessions.

Includes a regression test using a WPDB proxy to deterministically reproduce the race condition.
@github-actions
Copy link

Hi @mindctrl! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

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 westonruter, mindctrl, peterwilsoncc, joefusco, czarate.

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

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@peterwilsoncc
Copy link
Contributor

@mindctrl The transients API is designed in such a way that persistence isn't guaranteed. Data can be removed at any time, either by the cache being flushed or the transients been cleaned up.

Sites with multiple servers may use a shared cache or they may use a per server cache, for example, but even for single site servers they may be dropped during a deploy.

As it's inherently unreliable, I don't think this is an approach we can take.

@josephfusco
Copy link

Hey @mindctrl, I opened #11068 which builds on this same direction. Moved all sync storage to a dedicated table, with awareness in transients like your approach here.

@peterwilsoncc's point about transient reliability is worth discussing — awareness data is transient by nature (cursor positions, selections) and repopulates on the next poll, so a cache flush just means a brief flicker rather than data loss. Happy to explore alternatives if that's still a concern.

@mindctrl
Copy link
Author

@peterwilsoncc thanks for reviewing. To be clear, I don't love this idea, but given how late we are in the cycle, I wanted to try to reduce the amount of postmeta db operations without refactoring a lot of code. I'd much prefer a custom table.

Awareness syncing is the biggest "offender" here, because even when no content is changing and clients are idle, it's still updating the updated_at value for each client.

Since this is awareness state and not content data, it wouldn't be a lossy, destructive thing if the cache were cleared temporarily before the next awareness state sync, which would happen less than 1 second later. It would just appear that someone dropped offline very briefly.

* @param Closure(): T $callback Callback.
* @return T Return value from the callback.
*/
private function with_suspended_posts_last_changed_update( Closure $callback ) {
Copy link
Member

Choose a reason for hiding this comment

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

I see this is now only used in the add_update() method. Is it still even needed?

@chriszarate
Copy link

@mindctrl @westonruter Even as we explore a new table as our path forward, resolving the race condition in get_updates_after_cursor is extremely valuable to increase confidence in beta testing. Do you think we can merge this for beta 3?

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.

5 participants