Skip to content

Remaining per-request options query after priming (options are not autoloaded) #204

Closed

Description

@Contributolo

Since 7.7.6 (#152) Blockstudio loads seven options with one query in Plugin::prime_option_caches(). On a page view without a persistent object cache that query still runs on every request. Measured with a query profiler on two sites running 7.7.13, it is the only query Blockstudio makes on the front page: 1 of 18 queries on a small site, 1 of 64 on a multilingual one.

SELECT option_name, option_value FROM wp_options WHERE option_name IN ('blockstudio_settings', ...)
  < wp_prime_option_caches < Blockstudio\Plugin->prime_option_caches < Blockstudio\Plugin->init

Why it remains

wp_prime_option_caches() only skips options it finds in alloptions, in the object cache or in notoptions (option.php, the filter before the query). Without a persistent object cache the last two are empty when a request starts, so every listed option that is not autoloaded, whether it exists or not, keeps the query alive. As of 7.7.13 that applies to all seven:

Option Written Read
blockstudio_build_lock_cleanup_version autoload false, runtime-cache.php:153 runtime-cache.php:147
blockstudio_populate_cache_version autoload false, build-cache.php:441, :504 build-cache.php:386
blockstudio_collection_post_types_signature autoload false, pages.php:809 pages.php:805
blockstudio_pages_collection_manifests autoload false, pages.php:1207 pages.php:1218
blockstudio_pages_template_for autoload false, pages.php:1527 pages.php:1571
blockstudio_settings only by the migration, migrate.php:167 settings.php:463, :988
blockstudio_static_prerender_feature_state autoload true, deleted while prerendering is off (static-prerender-runtime.php:231, :2746) static-prerender-runtime.php:2722

The last two usually do not exist (no legacy settings to migrate, static prerendering off), and a missing option is never in alloptions.

Possible direction

  1. Write the five options Blockstudio maintains with autoload null instead of false. Since WordPress 6.6, null is auto: the row is autoloaded unless the value is larger than wp_max_autoloaded_option_size (150 KB by default), so a large collection manifest stays out of alloptions by itself. Existing rows switch once with wp_set_options_autoload() behind a small autoloaded version option.
  2. Do not leave the two usually missing options to priming: either store their empty state once as an autoloaded row, or read them only when the feature is in use.

With both, wp_prime_option_caches() finds everything in alloptions and returns before the query. Sites with a persistent object cache see no difference. The cost is a few small rows (version strings, a signature, a short array) in the autoload query WordPress runs anyway.

Happy to send a pull request if this direction works for you, or to follow a different preference for the two missing options.

Activity

  1. added
    enhancement
    on Nov 7, 2026
  2. dnnsjsk commented on Nov 10, 2026

    @dnnsjsk
    Contributor

    Sounds good, lets do it like that @Contributolo, thanks!

  3. added 2 commits that reference this issue on Nov 11, 2026
    e05e8a7
    823a2fd
  4. dnnsjsk commented on Nov 11, 2026

    @dnnsjsk
    Contributor

    Released in Blockstudio 7.7.14, via #207 and 823a2fd. Small request options are autoloaded, missing fallback rows are initialized, and large collection configuration keeps WordPress’s size-aware policy. Migration updates existing values in place and also runs for theme-bundled Composer installs. Regression coverage verifies the query count, migration paths, and persistent-cache behavior. Full CI and distribution checks pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions