[codex] Cache prepared get_blocks results per request#372
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_blocks()results for the current PHP request$no_cache = trueas a full bypass and clear the request cache when it is usedProblem
Sites that register many blocks programmatically with
lazyblocks()->add_block( $block_config )can callget_blocks()repeatedly during a single request. Each call prepared the same user blocks again, so pages with 50+ blocks could spend significant time rebuilding identical block data.Solution
The plugin now stores the prepared
get_blocks()result in an in-memory request-level cache keyed bydb_onlyandkeep_duplicates. The publiclzb/get_blocksfilter still runs on every return, while the heavierlzb/block_datapreparation work is reused within the request.$no_cache = truecontinues to bypass the cache and now clears any prepared request cache so forced rebuilds remain fresh.Validation
npm run test:unit:php -- --filter BlockRegistrationTestnpm run test:unit:phplzb/block_datapreparation dropped from about 380 calls per request to about 19Note: PHPUnit still reports existing config validation warnings for
processUniqueFilesand<filter>.