Skip to content

Commit

Permalink
fix: error deleting users with over 1000 requests
Browse files Browse the repository at this point in the history
Break-up request removal into groups of 1000 requests to be removed at a time.
  • Loading branch information
Zebebles committed Mar 5, 2023
1 parent a4d07f5 commit b47dac2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,14 @@ router.delete<{ id: string }>(
* we manually remove all requests from the user here so the parent media's
* properly reflect the change.
*/
await requestRepository.remove(user.requests);
await requestRepository.remove(user.requests, {
/**
* Break-up into groups of 1000 requests to be removed at a time.
* Necessary for users with >1000 requests, else an SQLite 'Expression tree is too large' error occurs.
* https://typeorm.io/repository-api#additional-options
*/
chunk: user.requests.length / 1000,
});

await userRepository.delete(user.id);
return res.status(200).json(user.filter());
Expand Down

0 comments on commit b47dac2

Please sign in to comment.