Skip to content

Commit

Permalink
Fix timeline fetch when using sinceId
Browse files Browse the repository at this point in the history
  • Loading branch information
tai-cha authored and kanarikanaru committed Mar 13, 2024
1 parent a56da01 commit 1e52d01
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/backend/src/core/FanoutTimelineEndpointService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ export class FanoutTimelineEndpointService {
shouldFallbackToDb = ps.useDbFallback && (redisResult.length > 1 && redisResult.some(ids => ids.length === 0));

// 取得したresultの中で最古のIDのうち、最も新しいものを取得
// shouldPrependがtrueの場合は最も新しいものを、falseの場合は最も古いものを取得
const thresholdId = shouldPrepend ? redisResult.map(ids => ids[ids.length - 1]).sort(idCompare)[0] : redisResult.map(ids => ids[0]).sort(idCompare)[0];
const thresholdId = redisResult.map(ids => ids[0]).sort()[0];

// TODO: いい感じにgetMulti内でソート済だからuniqするときにredisResultが全てソート済なのを利用して再ソートを避けたい
const redisResultIds = shouldFallbackToDb ? [] : Array.from(new Set(redisResult.flat(1))).filter(id => idCompare(id, thresholdId) === 1);
const redisResultIds = shouldFallbackToDb ? [] : Array.from(new Set(redisResult.flat(1)));

redisResultIds.sort(idCompare);
noteIds = redisResultIds.slice(0, ps.limit);
noteIds = redisResultIds.filter(id => id >= thresholdId).slice(0, ps.limit);

shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0);

Expand Down

0 comments on commit 1e52d01

Please sign in to comment.