Skip to content

[6.x] Avoid loading the revisions store when finding a working copy#14847

Merged
jasonvarga merged 1 commit into
6.xfrom
revision-findbyworkingcopy
Jun 19, 2026
Merged

[6.x] Avoid loading the revisions store when finding a working copy#14847
jasonvarga merged 1 commit into
6.xfrom
revision-findbyworkingcopy

Conversation

@jasonvarga

Copy link
Copy Markdown
Member

Summary

Resolving a single working copy via Revisions::findWorkingCopyByKey() ran a query against the revisions Stache store:

return $this->query()
    ->where('key', $key)
    ->where('action', 'working')
    ->first();

The first such call forces the revisions store's indexes to build, which loads every revision and working-copy file on the site into memory. A working copy is a single file at a deterministic path, so this reads it directly instead:

$path = $this->directory().'/'.$key.'/working.yaml';

if (! File::exists($path)) {
    return null;
}

return $this->store->makeItemFromFile($path, File::get($path));

This restores the pre-#10437 behaviour for this lookup while keeping the query builder for actual revision queries (whereKey(), CP revision history, etc.).

Why

Entry::workingCopy() / hasWorkingCopy() are called per-entry during Stache warming — e.g. via computed fields, or any values() call during URI index building. Before #10437 each call was a cheap file_exists(); afterwards each call could trigger a full warm of the revisions store.

On a real site (~3,600 entries in one collection, revisions enabled) this was the dominant cost of stache:warm. Isolated cold-load of that collection:

findWorkingCopyByKey time peak memory
query builder (current) 144s 2,224 MB
direct file read (this PR) 15s 728 MB

Fixes #14842.

Testing

Added coverage to tests/Revisions/RepositoryTest.php:

  • finds a working copy by key
  • returns null when there's no working copy
  • does not use the query builder (regression guard against re-loading the whole store)

Finding a single working copy went through the query builder, which forced
the entire revisions Stache store to load. A working copy is one file at a
deterministic path, so read it directly. This avoids warming the whole
revisions store when entries are checked for working copies during warming.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jasonvarga jasonvarga merged commit b1826cc into 6.x Jun 19, 2026
22 checks passed
@jasonvarga jasonvarga deleted the revision-findbyworkingcopy branch June 19, 2026 15:18
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.

Stache warming is ~3x slower in v6, preventing us from deploying our site

1 participant