From 6ca32a23b4433ba97a182d8b0bf9307fff7969ad Mon Sep 17 00:00:00 2001 From: gintil Date: Tue, 10 Dec 2024 07:55:03 -0500 Subject: [PATCH] Remove unnecessary db call --- .../src/articles/articles.service.ts | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/services/user-feeds/src/articles/articles.service.ts b/services/user-feeds/src/articles/articles.service.ts index 268a2928b..ad2601c92 100644 --- a/services/user-feeds/src/articles/articles.service.ts +++ b/services/user-feeds/src/articles/articles.service.ts @@ -445,6 +445,19 @@ export class ArticlesService { newArticles, storedComparisons ); + + if (debug) { + logger.datadog( + `Debug feed ${id}: ${articlesPastBlocks.length} articles past blocking comparisons`, + { + articles: articlesPastBlocks.map((a) => ({ + id: a.flattened.id, + title: a.flattened.title, + })), + } + ); + } + const articlesPassedComparisons = await this.checkPassingComparisons( { id, @@ -454,6 +467,18 @@ export class ArticlesService { storedComparisons ); + if (debug) { + logger.datadog( + `Debug feed ${id}: ${articlesPassedComparisons.length} articles past passing comparisons`, + { + articles: articlesPassedComparisons.map((a) => ({ + id: a.flattened.id, + title: a.flattened.title, + })), + } + ); + } + // any new comparisons stored must re-store all articles if (newArticles.length > 0) { await this.storeArticles(id, newArticles, { @@ -840,29 +865,14 @@ export class ArticlesService { return []; } - const storedComparisonResults = await this.areComparisonsStored( - id, - passingComparisons - ); - - const relevantComparisons = storedComparisonResults - .filter((r) => r.isStored) - .map((r) => r.field); - - if (relevantComparisons.length === 0) { - /** - * Just store the comparison values, otherwise all articles would get delivered since none - * of the comparison values have been seen before. - */ - return []; - } + // All passing comparisons are confirmed to be stored const articlesToSend = await Promise.all( seenArticles.map(async (article) => { const shouldPass = await this.articleFieldsSeenBefore( id, article, - relevantComparisons + currentlyStoredComparisons ); return shouldPass ? null : article;