diff --git a/packages/api/src/jobs/update_home.ts b/packages/api/src/jobs/update_home.ts index dd09639dc..d60d4a3e4 100644 --- a/packages/api/src/jobs/update_home.ts +++ b/packages/api/src/jobs/update_home.ts @@ -209,7 +209,7 @@ const rankCandidates = async ( return candidates } -const redisKey = (userId: string) => `just-read-feed:${userId}` +const redisKey = (userId: string) => `home:${userId}` const MAX_FEED_ITEMS = 500 export const getHomeSections = async ( @@ -251,7 +251,7 @@ export const getHomeSections = async ( const appendSectionsToHome = async ( userId: string, sections: Array
, - cursor = Date.now() + cursor?: number ) => { const redisClient = redisDataSource.redisClient if (!redisClient) { @@ -263,11 +263,14 @@ const appendSectionsToHome = async ( // store candidates in redis sorted set const pipeline = redisClient.pipeline() - const offset = sections.length + 86_400_000 - cursor = cursor - offset + // sections expire in 24 hours + const ttl = 86_400_000 + + const batchSize = sections.length + const savedAt = cursor ? cursor - batchSize - ttl : Date.now() const scoreMembers = sections.flatMap((section, index) => [ - cursor + index + 86_400_000, // sections expire in 24 hours + savedAt + index + ttl, // score for the section is the savedAt + index + ttl JSON.stringify(section), ]) diff --git a/packages/api/src/resolvers/home/index.ts b/packages/api/src/resolvers/home/index.ts index 64a14503d..acb7f89e5 100644 --- a/packages/api/src/resolvers/home/index.ts +++ b/packages/api/src/resolvers/home/index.ts @@ -56,6 +56,8 @@ export const homeResolver = authorized< } } + const endCursor = sections[sections.length - 1].score.toString() + const edges = sections.map((section) => ({ cursor: section.score.toString(), node: section.member, @@ -64,8 +66,10 @@ export const homeResolver = authorized< return { edges, pageInfo: { - hasPreviousPage: true, // there is always a previous page for new items - hasNextPage: true, // there is always a next page for old items + startCursor: after, + endCursor, + hasPreviousPage: true, // there is always a previous page for newer items + hasNextPage: true, // there is always a next page for older items }, } })