Skip to content

Add a corpus filter on Element.objects.trash

https://redmine.teklia.com/issues/11576

Some deletions through .trash(delete_children=True) are not going through in prod because the child element deletion only uses a filter on ElementPaths. PostgreSQL thinks there are so many rows that an index is irrelevant, and uses a sequential scan on ElementPaths.

Adding a filter on corpus_id seems to convince PostgreSQL that it can use indices again, because the corpus filtering will reduce the rows to look up through the ElementPaths. We need to check if other databases behave the same and whether or not this breaks anything though.

This will imply that deleting an element will put ElementPaths in an inconsistent state if some child elements were not in the same corpus, but this would probably break various other APIs anyway.