Skip to content

[6.x] Find which entries are published once when building the entries_count index - #15898

Open
DanielDarrenJones wants to merge 2 commits into
statamic:6.xfrom
DanielDarrenJones:perf/6x-entries-count-index-build
Open

DanielDarrenJones wants to merge 2 commits into
statamic:6.xfrom
DanielDarrenJones:perf/6x-entries-count-index-build

Conversation

@DanielDarrenJones

Copy link
Copy Markdown
Contributor

The entries_count term index (used when terms are filtered or sorted by it, such as min_count on the taxonomy tag) is built by asking for each term's published entries one term at a time. Each of those is a query over every entry, so the build grows with terms × entries.

This finds which of the associated entries are published with one query, then counts each term from the associations the index already reads.

On a generated site of 11,771 entries and 2,446 terms (6.42.0, CPU time, two runs each):

Taxonomy Terms in index Before After
categories 24 0.74 s 0.08 s
tags 400 8.6 s 0.13 s
keywords 2,022 43.1 s 0.29 s

The index values are identical before and after (compared serialized, all three taxonomies).

Where this build happens during a request rather than a warm, that request is the one waiting for it.

Kept as they were:

  • A single term being updated (a save) still counts through Term::entriesCount().
  • A term repository that overrides entriesCount() is still asked for each term.

The new test counts entry queries while the index is built: 11 before, 1 after.

Found by @godismyjudge95, who measured this on a much larger site and shared the approach.

This branch has not been deployed

No deployments
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.

1 participant