From ef52c03dfa73b5018ac41647586539ff88412f98 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 15 Sep 2023 22:35:58 +0800 Subject: [PATCH] Add a max count to RSS refreshes --- packages/rss-handler/src/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/rss-handler/src/index.ts b/packages/rss-handler/src/index.ts index afc64c1e3..074554bd3 100644 --- a/packages/rss-handler/src/index.ts +++ b/packages/rss-handler/src/index.ts @@ -187,6 +187,7 @@ export const rssHandler = Sentry.GCPFunction.wrapHttpFunction( let lastValidItem: Item | null = null // fetch feed + let itemCount = 0 const feed = await parser.parseURL(feedUrl) console.log('Fetched feed', feed.title, new Date()) @@ -220,6 +221,11 @@ export const rssHandler = Sentry.GCPFunction.wrapHttpFunction( lastValidItem = item } + // Max limit per-feed update + if (itemCount > 99) { + continue + } + // skip old items and items that were published before 24h if ( publishedAt < new Date(lastFetchedAt) || @@ -239,6 +245,8 @@ export const rssHandler = Sentry.GCPFunction.wrapHttpFunction( if (!lastItemFetchedAt || publishedAt > lastItemFetchedAt) { lastItemFetchedAt = publishedAt } + + itemCount = itemCount + 1 } // no items saved