Skip to content

Create one sync storage post per room#3

Merged
chriszarate merged 2 commits intoadd/collaboration-functionalityfrom
improve/collaboration-sync-posts
Feb 19, 2026
Merged

Create one sync storage post per room#3
chriszarate merged 2 commits intoadd/collaboration-functionalityfrom
improve/collaboration-sync-posts

Conversation

@chriszarate
Copy link
Owner

Create one sync storage post per room for storing sync updates instead of one singleton post.

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

In the base PR, @mindcrtl noted:

One of my first questions, which was already asked by @TimothyBJacobs, is related to the use of a single wp_sync_storage post.

Unless I'm misreading it, when add_post_meta, update_post_meta, and delete_post_meta are called, they invalidate all the cached meta for that post ID, but because every room shares the same wp_sync_storage post, that means all cached sync data across all rooms is invalidated. It's hard to understand why an editing session on post ID 1 should impact the caching and performance of a session on post ID 2.

In testing with 3 clients, I'm seeing thousands of post meta function calls within minutes. I think some of that could be alleviated by giving each room its own wp_sync_storage post, so that meta cache invalidation is scoped to a single session rather than all of them.

This implements that suggestion, creating one wp_sync_storage post per room and storing updates in post meta against each post.

Choose a reason for hiding this comment

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

This could become a const now instead.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done in c90ca32

* @var array<string, int>
*/
private static ?int $storage_post_id = null;
private static array $storage_post_ids = array();

Choose a reason for hiding this comment

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

In practice, will there ever be more than one ID in this array for a given request?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, because all sync requests for a given client are batched into a single request. If you inspect a request payload, you will see something like:

Screenshot 2026-02-18 at 23 11 37

The post IDs are cached because post meta is accessed multiple times, once for awareness state and at least once for sync updates.

@chriszarate
Copy link
Owner Author

I've given this some good testing, it's straightforward, and the feedback suggests that is an impactful improvement. Therefore I'm going to merge it into the base branch. Feel free to leave additional feedback on that PR.

@chriszarate chriszarate merged commit e7c9ecb into add/collaboration-functionality Feb 19, 2026
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.

2 participants

Comments