Skip to content

[6.x] Write each index once when a structured collection is reordered - #15888

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
DanielDarrenJones:perf/6x-structured-index-updates
Nov 13, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
DanielDarrenJones:perf/6x-structured-index-updates

Conversation

@DanielDarrenJones

Copy link
Copy Markdown
Contributor

Reordering a structured collection writes the order and parent indexes once for every entry whose position changed.

CollectionEntriesStore::updateEntriesWithinIndex() calls Index::updateItem() for each affected entry, and each call loads the index, sets one value and writes the whole index back to the cache. Dragging the first item of a long list to the end changes the order of every entry, so a 2,000 entry collection does 4,000 writes of a 2,000 item index to move one row.

This adds Index::updateItems(), which loads the index once, sets every item and writes it once. updateEntriesWithinIndex() uses it. An index class that has its own updateItem() still has it called for each item, so custom indexes behave as they did.

Numbers

Dragging the first entry of a structured collection to the end, timed in a fresh process, flat-file Stache in the file cache:

entries index writes before after time before after
500 1,000 2 ~240 ms ~115 ms
2,000 4,000 2 ~1,100 ms ~440 ms

The contents of the indexes afterwards are the same as before.

Tests

The order and parent indexes are each written once for a reorder touching several entries, hold the same values as before, and an index with its own updateItem() still has it used. Two of the four fail without the change.

Reordering a collection's tree, or changing a page that has children, updates
the order, parent and uri indexes for each entry affected, and each update
wrote the whole index. They are all put first now and the index is written
once. An index class with its own updateItem() is still called for each.
@jasonvarga
jasonvarga merged commit 575bd33 into statamic:6.x Nov 13, 2026
62 checks passed
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