Structured entry order goes stale for entries shifted, but not moved, by a tree change
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 54/100
Direção de pesquisa
Start by reading UpdateStructuredEntryOrderAndParent and trace how it uses the tree diff to update flattened entry order; the report also points to CollectionEntriesStore::updateOrders($ids) for the Stache path. Reproduce the A/a1/B/b1 example, then check that adding a2 or moving an entry leaves every stored order matching the flattened tree. Consider the reported concern about the number of saves for large trees.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Bug description
When a collection tree is saved, UpdateStructuredEntryOrderAndParent only updates the order of entries in $diff->moved() and $diff->added() (plus the descendants of moved entries). An entry's order is its position in the whole flattened tree though, so any entry whose flattened position shifts without its own parent or index changing keeps its old order value.
With the Eloquent driver that value is stored in entries.order, and structured collections are sorted by it on the front end (e.g. the collection tag's default sort), so over time the site drifts away from the tree in the CP, with ties and items in the wrong place. We had a client report that reordering in the CP wasn't being reflected on the site, and on that database around 1,300 of 3,700 structured entries had a stale order.
How to reproduce
- Create a structured collection with this tree:
The stored orders are A = 1, a1 = 2, B = 3, b1 = 4.- A - a1 - B - b1 - Add a new entry
a2as a child ofA, so the tree flattens to A, a1, a2, B, b1. a2gets order 3, butBandb1aren't inmoved()as their path and index haven't changed, so they keep 3 and 4.Bnow ties witha2,b1has 4 rather than 5, andEntry::query()->where('collection', 'x')->orderBy('order')(or{{ collection:x }}) no longer matches the tree.
The same happens when an entry is moved within one branch, as every entry after it in other branches shifts but isn't updated.
Logs
No response
Environment
Environment
Laravel Version: 12.70.0
PHP Version: 8.4.27
Composer Version: 2.10.3
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 5
Sites: 42 (English, Dutch, Russian, and 39 more)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 6.35.1 PRO
Statamic Addons
aryehraber/statamic-captcha: 1.18.0
aryehraber/statamic-logbook: 4.1.0
mitydigital/sitemapamic: 3.5.1
statamic/eloquent-driver: 5.12.3
statamic/ssg: 4.1.0
Statamic Eloquent Driver
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Installation
Existing Laravel app
Additional details
I've only confirmed this with the Eloquent driver. From reading the code I think the Stache's order index would go stale in the same way, as CollectionEntriesStore::updateOrders($ids) only calls updateItem() for the ids it's given, but it's rebuilt on stache:warm so it's probably much less noticeable there.
One option would be to work out the affected ids by comparing each entry's position in the old and new flattened trees, rather than its path and index. I appreciate that could mean a lot of saves on bigger trees (statamic/eloquent-driver#105), so happy to go with whichever approach you'd prefer.
For now we've worked around it with a CollectionTreeSaved listener that writes each entry's flattened position straight to the order column, only for rows where it's wrong.
- Linguagem predominante
- PHP
- Estrelas
- 4.9k
- Forks
- 647
- Merge médio
- 1d 45min
- PRs com merge (30d)
- 221
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de statamic/cms
-
forms ui
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
accessibility
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
Mantenedores costumam responder em até 1 dia
-
antlers
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia
-
Nav: link to the site root with an anchor (/#section) gets is_parent on every pageTalvez já em andamento @duncanmcclean assumiu hoje. Abertanavigations
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
Mantenedores costumam responder em até 1 dia
-
Multiple Choice and Checkboxes no longer offer "Inline", but the default views still use itTalvez já em andamento @duncanmcclean assumiu hoje. Abertaforms
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
Mantenedores costumam responder em até 1 dia
Todas as issues de statamic/cms
Issues semelhantes
-
sync-en
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 86/100
Mantenedores costumam responder em até 1 dia
-
Selection on a line without a docblock tag drops trailing characters (data provider attribute)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
vimeo/psalm#15150 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
taskforcesh/bullmq#5238 ·
Mantenedores costumam responder em até 1 dia
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itTalvez já em andamento @bfs2021 assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Automattic/jetpack#55517 ·
Mantenedores costumam responder em até 1 dia