ユーザーTLではFTTのソースが空の際にDBにFallbackしないように
This commit is contained in:
parent
3564bf5c66
commit
48232ca57b
|
@ -34,6 +34,7 @@ type TimelineOptions = {
|
||||||
excludeReplies?: boolean;
|
excludeReplies?: boolean;
|
||||||
excludePureRenotes: boolean;
|
excludePureRenotes: boolean;
|
||||||
dbFallback: (untilId: string | null, sinceId: string | null, limit: number) => Promise<MiNote[]>,
|
dbFallback: (untilId: string | null, sinceId: string | null, limit: number) => Promise<MiNote[]>,
|
||||||
|
preventEmptyTimelineDbFallback?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -63,8 +64,9 @@ export class FanoutTimelineEndpointService {
|
||||||
|
|
||||||
const redisResult = await this.fanoutTimelineService.getMulti(ps.redisTimelines, ps.untilId, ps.sinceId);
|
const redisResult = await this.fanoutTimelineService.getMulti(ps.redisTimelines, ps.untilId, ps.sinceId);
|
||||||
|
|
||||||
// 取得したredisResultのうち、2つ以上ソースがあり、1つでも空であればDBにフォールバックする
|
// オプション無効時、取得したredisResultのうち、2つ以上ソースがあり、1つでも空であればDBにフォールバックする
|
||||||
let shouldFallbackToDb = ps.useDbFallback && (redisResult.length > 1 && redisResult.some(ids => ids.length === 0));
|
let shouldFallbackToDb = ps.useDbFallback &&
|
||||||
|
(ps.preventEmptyTimelineDbFallback !== true && redisResult.length > 1 && redisResult.some(ids => ids.length === 0));
|
||||||
|
|
||||||
// 取得したresultの中で最古のIDのうち、最も新しいものを取得
|
// 取得したresultの中で最古のIDのうち、最も新しいものを取得
|
||||||
const fttThresholdId = redisResult.map(ids => ids[0]).sort()[0];
|
const fttThresholdId = redisResult.map(ids => ids[0]).sort()[0];
|
||||||
|
@ -75,7 +77,7 @@ export class FanoutTimelineEndpointService {
|
||||||
let noteIds = redisResultIds.filter(id => id >= fttThresholdId).slice(0, ps.limit);
|
let noteIds = redisResultIds.filter(id => id >= fttThresholdId).slice(0, ps.limit);
|
||||||
|
|
||||||
const oldestNoteId = ascending ? redisResultIds[0] : redisResultIds[redisResultIds.length - 1];
|
const oldestNoteId = ascending ? redisResultIds[0] : redisResultIds[redisResultIds.length - 1];
|
||||||
shouldFallbackToDb ||= noteIds.length === 0 || ps.sinceId != null && ps.sinceId < oldestNoteId;
|
shouldFallbackToDb ||= ps.useDbFallback && (noteIds.length === 0 || ps.sinceId != null && ps.sinceId < oldestNoteId);
|
||||||
|
|
||||||
if (!shouldFallbackToDb) {
|
if (!shouldFallbackToDb) {
|
||||||
let filter = ps.noteFilter ?? (_note => true);
|
let filter = ps.noteFilter ?? (_note => true);
|
||||||
|
|
|
@ -143,6 +143,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
withFiles: ps.withFiles,
|
withFiles: ps.withFiles,
|
||||||
withRenotes: ps.withRenotes,
|
withRenotes: ps.withRenotes,
|
||||||
}, me),
|
}, me),
|
||||||
|
preventEmptyTimelineDbFallback: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return timeline;
|
return timeline;
|
||||||
|
|
Loading…
Reference in New Issue