Skip to content

perf: skip populate cache refresh for edit lock and session meta - #147

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/populate-ignore-edit-lock
Oct 22, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/populate-ignore-edit-lock

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Every meta write rotates the populate cache version (includes/classes/build-cache.php, the meta hooks in init() call invalidate_populate_cache()). WordPress writes some keys purely as bookkeeping:

  • _edit_lock from wp_set_post_lock() when an editor opens and from wp_refresh_post_lock() on every Heartbeat tick (wp-admin/includes/post.php, wp-admin/includes/misc.php)
  • _edit_last next to a post save that already invalidates through save_post
  • session_tokens on every login and logout (wp-includes/class-wp-user-meta-session-tokens.php)

None of them can change what populate returns, but while anyone keeps an editor open, populated choices are rebuilt and the runtime cache file is rewritten about every 30 seconds.

The meta hooks now pass the meta key to a small wrapper, invalidate_populate_cache_for_meta(). It skips the keys in the new blockstudio/cache/populate_ignored_meta_keys filter, which defaults to those three, so integrators can add their own high-frequency keys. save_post and all other writes still invalidate.

Measured in Playground with a theme that uses custom populate in a block and an extension: a two-minute editing session with a lock refresh every 15 seconds caused 5 version rotations and 5 rewrites of the 48 KB runtime cache file before the change, and 0 after. A regular meta write still refreshes the choices.

Test: BuildCacheTest::test_editing_and_login_bookkeeping_meta_does_not_rotate_the_populate_version fails on main and passes with the change; PopulateTest passes before and after. Docs for the filter are in blocks/hooks/php.md and general/settings.md. I used @since 7.7.6 on the filter, adjust as you like.

_edit_lock (editor open and every Heartbeat tick), _edit_last and
session_tokens are bookkeeping and cannot change populated choices.
Ignore them, extendable through blockstudio/cache/populate_ignored_meta_keys.
@dnnsjsk
dnnsjsk merged commit 7b0a3c6 into inline0:main Oct 22, 2026
@dnnsjsk

dnnsjsk commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Included in Blockstudio 7.7.6, now officially released. This PR is merged into main as part of the reviewed release, with full CI and distribution checks passing for the release commit.

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