From ac77b037d5fb0c54f5edf4b29d04adb57aef388f Mon Sep 17 00:00:00 2001 From: Zeb Muller Date: Thu, 11 May 2023 11:45:23 +1000 Subject: [PATCH] fix: error deleting users with over 1000 requests (#3376) Break-up request removal into groups of 1000 requests to be removed at a time. --- server/routes/user/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index ea709caf5..94784df51 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -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());