Skip to content

Commit

Permalink
Add case of old fast posts from slow feeds to fast categories
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jan 17, 2024
1 parent 37b4a34 commit 7b0b914
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/fast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,29 @@ function notEmpty<Value>(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<string, CategoryValue> = {}
for (let feed of [...fastFeeds, ...filterFeeds]) {
for (let feed of [...fastFeeds, ...filterFeeds, ...missedFeeds]) {
let id = feed.categoryId
if (!uniqueCategories[id]) {
if (id === 'general') {
Expand Down
14 changes: 14 additions & 0 deletions core/test/fast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {})
Expand Down

0 comments on commit 7b0b914

Please sign in to comment.