RTC: Add optional shouldSync function to entity sync config#76947
RTC: Add optional shouldSync function to entity sync config#76947alecgeatches merged 3 commits intotrunkfrom
shouldSync function to entity sync config#76947Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +44 B (0%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 2d20936. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24095556867
|
alecgeatches
left a comment
There was a problem hiding this comment.
Makes sense to me! Will merge when tests pass.
What?
Add optional
shouldSyncfunction to entity sync config to control whether an entity or entity collection should be synced.Closes #76932
Why?
In #76932, @mmtr notes that when a
core/commentsblock is added to a post with existing comments, each comment is loaded for syncing, even though there is no possibility of collaborating on those comments. This contributes to unnecessary resource usage: additional WebSocket connections (if using a WebSocket provider) or additional database storage (if using the default polling provider).The root cause is that the
commententity is used for both regular post comments and block comments. By enabling sync for block comments, we also enable syncing for regular post comments.It might be ideal to represent block comments as a separate entity (e.g.,
blockComment) that targets the same REST API endpoint ascomment. However, this would require changes both to the block comments feature as well as the permissions system.An alternative approach, taken in this PR, is to add an optional
shouldSyncfunction to the entity sync config, allowing it to control whether specific entities or entity collections should be loaded. This will probably find utility in other circumstances. Often, we want to sync individual entities but not the collection, or vice versa. We might also want a way to sync specific entity subtypes while excluding others.How?
Add an optional
shouldSyncfunction to the entity sync config. If it is present and returnsfalse, the entity or collection are not synced.Testing Instructions
1/ "Hello world") and open it for editing./wp-json/wp-sync/v1/updates.root/comment:nwherenis the comment ID.