Skip to content

Commit

Permalink
fix(backend): DBフォールバック有効時、複数のFTTソースから取得するタイムラインで取得漏れが起きる現象の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tai-cha committed Mar 2, 2024
1 parent eb60460 commit 82bec76
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/backend/src/core/FanoutTimelineEndpointService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ export class FanoutTimelineEndpointService {

const redisResult = await this.fanoutTimelineService.getMulti(ps.redisTimelines, ps.untilId, ps.sinceId);

// 取得したredisResultのうち、2つ以上ソースがあり、1つでも空であればDBにフォールバックする
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];

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

redisResultIds.sort(idCompare);
noteIds = redisResultIds.slice(0, ps.limit);
Expand Down

0 comments on commit 82bec76

Please sign in to comment.