From f54fa0ad02efd7cf4e66db15ed809a9b035cc85a Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 23 May 2023 22:56:27 +0200 Subject: [PATCH] server: remove unnecessary complex loop --- .../src/queue/processors/db/delete-account.ts | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/backend/src/queue/processors/db/delete-account.ts b/packages/backend/src/queue/processors/db/delete-account.ts index 84e28f25d..0bdf8c5af 100644 --- a/packages/backend/src/queue/processors/db/delete-account.ts +++ b/packages/backend/src/queue/processors/db/delete-account.ts @@ -46,29 +46,17 @@ export async function deleteAccount(job: Bull.Job): Promise } { // Delete files - let cursor: DriveFile['id'] | null = null; + const files = await DriveFiles.find({ + where: { + userId: user.id, + }, + order: { + id: 1, + }, + }) as DriveFile[]; - while (true) { - const files = await DriveFiles.find({ - where: { - userId: user.id, - ...(cursor ? { id: MoreThan(cursor) } : {}), - }, - take: 10, - order: { - id: 1, - }, - }) as DriveFile[]; - - if (files.length === 0) { - break; - } - - cursor = files[files.length - 1].id; - - for (const file of files) { - await deleteFileSync(file); - } + for (const file of files) { + await deleteFileSync(file); } logger.succ('All of files deleted');