From 9415f38915e8346f105c05c411aa470fe38b1253 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Thu, 16 Sep 2021 12:47:31 +0200 Subject: [PATCH] chore: Simplify acestor loop Signed-off-by: Johan Haals --- .../src/next/database/DefaultProcessingDatabase.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts b/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts index 5fc6f96920..8ba9d54b8f 100644 --- a/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts +++ b/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.ts @@ -527,14 +527,7 @@ export class DefaultProcessingDatabase implements ProcessingDatabase { const entityRefs = new Array(); let currentRef = entityRef.toLocaleLowerCase('en-US'); - let depth = 0; - for (;;) { - if (depth++ > MAX_ANCESTOR_DEPTH) { - throw new Error( - `Unable receive ancestors for ${entityRef}, reached maximum depth of ${MAX_ANCESTOR_DEPTH}`, - ); - } - + for (let depth = 1; depth <= MAX_ANCESTOR_DEPTH; depth += 1) { const rows = await tx( 'refresh_state_references', ) @@ -559,6 +552,9 @@ export class DefaultProcessingDatabase implements ProcessingDatabase { entityRefs.push(parentRef); currentRef = parentRef; } + throw new Error( + `Unable receive ancestors for ${entityRef}, reached maximum depth of ${MAX_ANCESTOR_DEPTH}`, + ); } async refresh(txOpaque: Transaction, options: RefreshOptions): Promise {