Closed DazWorrall closed 1 week ago
I think we should just do Model.where(stack_id: xxx).limit(1000).delete_all
in a loop until delete all return something < 1000
.
This way you don't need the select.
(not 100% sure all 3 DBs support DELETE/LIMIT though)
Follow on: #1376
^ That PR didn't quite work, so I went a little deeper. Before that PR we ran a query that looked something like:
... this is an indexed lookup:
... however given the sheer amount of rows involved, the query times out or hits lock contention.
My PR changed the query to something like
...but that's a table scan:
Which also fails 🙃
Take two is to split the select and delete into separate, indexed queries, ran in batches. I also pre-emptively do this for
Shipit::Commit
as it uses the same pattern so could be affected in the same way.