From 4eeb012b787199efb01e081532296ca5b45bc337 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Sat, 20 Jan 2024 11:36:10 +0800 Subject: [PATCH] Pass lits of fetchContentTasks into rss handlers This prevents the list from growing on each run --- packages/api/src/jobs/rss/refreshFeed.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/api/src/jobs/rss/refreshFeed.ts b/packages/api/src/jobs/rss/refreshFeed.ts index 9e60d4cc5..771e4ab9c 100644 --- a/packages/api/src/jobs/rss/refreshFeed.ts +++ b/packages/api/src/jobs/rss/refreshFeed.ts @@ -70,8 +70,6 @@ interface FetchContentTask { item: RssFeedItem } -const fetchContentTasks = new Map() // url -> FetchContentTask - export const isOldItem = (item: RssFeedItem, lastFetchedAt: number) => { // existing items and items that were published before 24h const publishedAt = item.isoDate ? new Date(item.isoDate) : new Date() @@ -288,6 +286,7 @@ const isItemRecentlySaved = async (userId: string, url: string) => { } const addFetchContentTask = ( + fetchContentTasks: Map, userId: string, folder: FolderType, item: RssFeedItem @@ -307,6 +306,7 @@ const addFetchContentTask = ( } const createTask = async ( + fetchContentTasks: Map, userId: string, feedUrl: string, item: RssFeedItem, @@ -324,7 +324,7 @@ const createTask = async ( } console.log(`adding fetch content task ${userId} ${item.link.trim()}`) - return addFetchContentTask(userId, folder, item) + return addFetchContentTask(fetchContentTasks, userId, folder, item) } const fetchContentAndCreateItem = async ( @@ -482,6 +482,7 @@ const getLink = (links: RssFeedItemLink[]): string | undefined => { } const processSubscription = async ( + fetchContentTasks: Map, subscriptionId: string, userId: string, feedUrl: string, @@ -562,6 +563,7 @@ const processSubscription = async ( } const created = await createTask( + fetchContentTasks, userId, feedUrl, feedItem, @@ -591,6 +593,7 @@ const processSubscription = async ( // the feed has never been fetched, save at least the last valid item const created = await createTask( + fetchContentTasks, userId, feedUrl, lastValidItem, @@ -673,9 +676,11 @@ export const _refreshFeed = async (request: RefreshFeedRequest) => { console.log('Fetched feed', feed.title, new Date()) + const fetchContentTasks = new Map() // url -> FetchContentTask // process each subscription sequentially for (let i = 0; i < subscriptionIds.length; i++) { await processSubscription( + fetchContentTasks, subscriptionIds[i], userIds[i], feedUrl,