Fix timeline fetch when using sinceId

This commit is contained in:
taichanne30 2024-03-07 01:47:41 +09:00
parent 5615675991
commit 4a8ffe20a7
No known key found for this signature in database
GPG Key ID: 1D5EE39F870DC283
1 changed files with 3 additions and 4 deletions

View File

@ -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);