From 7b0b9149b2cac610bf92af288f990dfd778ec61a Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Thu, 18 Jan 2024 00:13:40 +0100 Subject: [PATCH] Add case of old fast posts from slow feeds to fast categories --- core/fast.ts | 19 ++++++++++++++++--- core/test/fast.test.ts | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/core/fast.ts b/core/fast.ts index e60058ce..0ed64a98 100644 --- a/core/fast.ts +++ b/core/fast.ts @@ -21,16 +21,29 @@ function notEmpty(array: Value[]): array is [Value, ...Value[]] { async function findFastCategories(): Promise< [CategoryValue, ...CategoryValue[]] > { - let [fastFeeds, fastFilters, categories] = await Promise.all([ + let [fastFeeds, fastFilters, categories, fastPosts] = await Promise.all([ loadList(getFeeds({ reading: 'fast' })), loadList(getFilters({ action: 'fast' })), - loadValue(getCategories()) + loadValue(getCategories()), + loadList(getPosts({ reading: 'fast' })) ]) let filterFeeds = await Promise.all( fastFilters.map(i => loadValue(getFeed(i.feedId))) ) + let missedFeedIds = fastPosts + .map(i => i.feedId) + .filter(feedId => { + return ( + !fastFeeds.some(i => i.id === feedId) && + !filterFeeds.some(i => i.id === feedId) + ) + }) + let missedFeeds = await Promise.all( + missedFeedIds.map(id => loadValue(getFeed(id))) + ) + let uniqueCategories: Record = {} - for (let feed of [...fastFeeds, ...filterFeeds]) { + for (let feed of [...fastFeeds, ...filterFeeds, ...missedFeeds]) { let id = feed.categoryId if (!uniqueCategories[id]) { if (id === 'general') { diff --git a/core/test/fast.test.ts b/core/test/fast.test.ts index 47d26f53..54a4f767 100644 --- a/core/test/fast.test.ts +++ b/core/test/fast.test.ts @@ -122,6 +122,20 @@ test('is ready for unknown categories in fast category', async () => { }) }) +test('is ready for fast post in slow feed', async () => { + let categoryA = await addCategory({ title: 'A' }) + let feed = await addFeed(testFeed({ categoryId: categoryA, reading: 'slow' })) + await addPost(testPost({ feedId: feed, reading: 'fast' })) + + fastCategories.listen(() => {}) + await setTimeout(100) + + deepStrictEqual(fastCategories.get(), { + categories: [{ id: categoryA, isLoading: false, title: 'A' }], + isLoading: false + }) +}) + test('loads page when we have no fast posts', async () => { constantFastReading.listen(() => {}) fastPosts.listen(() => {})