From 8a63cc07f4f7b49ec43256bbec314852f0879a9b Mon Sep 17 00:00:00 2001 From: evlist Date: Sun, 12 Feb 2023 14:41:19 +0100 Subject: [PATCH] Bug fix (forEech and promises...) --- src/db-admin/health-legacy.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/db-admin/health-legacy.ts b/src/db-admin/health-legacy.ts index 111654d..b7fd53a 100644 --- a/src/db-admin/health-legacy.ts +++ b/src/db-admin/health-legacy.ts @@ -20,7 +20,7 @@ export { state }; export const watchDbLegacy = async () => { createRoot(async (dispose) => { - console.log({ caller: 'watchDbLegacy' }); + console.log({ caller: 'watchDbLegacy / start' }); db = globalThis.db; localDb = globalThis.localDb; @@ -189,9 +189,9 @@ export const watchDbLegacy = async () => { deletedDocs, state: state(), }); - - deletedDocs.forEach(async (doc) => { - await sleep(500); + let i = 0; + for (const doc of deletedDocs) { + await sleep(50); try { await db.purge(doc.id, doc.rev); } catch (err) { @@ -201,7 +201,16 @@ export const watchDbLegacy = async () => { err, }); } - }); + i = i + 1; + if (i % 10 === 0) { + console.log({ + caller: 'watchDbLegacy / purge', + nbDeletedDocs: i, + nbDocsToDelete: deletedDocs.length, + doc, + }); + } + } } await sleep(60000); }