[keyserver] Improve SQL performance in deleteThread
Summary:
Noticed that deleteThread performance was horrendous... the query took like 15min, and it took locks on a bunch of tables while it was ongoing.
We had a similar problem for deleteAccount that was solved in D1288 by splitting up the query, so I decided to do the same thing here.
Test Plan:
- Performance: I tested the query on my production keyserver and found that it took less than 0.1s.
- Correctness: I created a channel in my local dev environment, and then deleted it from the UI. I looked into the database and confirmed that the relevant rows were deleted.
Reviewers: tomek, atul
Reviewed By: atul
Differential Revision: https://phab.comm.dev/D8837