[keyserver] Improve SQL performance in deleteInaccessibleThreads
Summary:
This has a similar problem to the parent diff. I refactored it to use two queries, the second of which is the same as in the parent diff.
Depends on D8837
Test Plan:
- Performance: I tested the query on my production keyserver and found that it took less than 0.1s.
- Correctness: I created an "inaccessible thread" in my local dev environment by manually running an INSERT INTO threads query. I then triggered the cronjob manually by changing the time it runs, and confirmed my new thread was deleted. I also ran it when no threads needed to be deleted, and confirmed nothing happened via console.loging the code in the function.
Reviewers: tomek, atul
Reviewed By: atul
Differential Revision: https://phab.comm.dev/D8838