Skip to content

Commit

Permalink
ユーザーTLではFTTのソースが空の際にDBにFallbackしないように
Browse files Browse the repository at this point in the history
(cherry picked from commit 48232ca)
  • Loading branch information
tai-cha authored and anatawa12 committed Jul 31, 2024
1 parent a62afbf commit 1999a5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/backend/src/core/FanoutTimelineEndpointService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type TimelineOptions = {
excludeReplies?: boolean;
excludePureRenotes: boolean;
dbFallback: (untilId: string | null, sinceId: string | null, limit: number) => Promise<MiNote[]>,
preventEmptyTimelineDbFallback?: boolean;
};

@Injectable()
Expand Down Expand Up @@ -63,8 +64,9 @@ export class FanoutTimelineEndpointService {

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

// 取得したredisResultのうち、2つ以上ソースがあり、1つでも空であればDBにフォールバックする
let shouldFallbackToDb = ps.useDbFallback && (redisResult.length > 1 && redisResult.some(ids => ids.length === 0));
// オプション無効時、取得したredisResultのうち、2つ以上ソースがあり、1つでも空であればDBにフォールバックする
let shouldFallbackToDb = ps.useDbFallback &&
(ps.preventEmptyTimelineDbFallback !== true && redisResult.length > 1 && redisResult.some(ids => ids.length === 0));

// 取得したresultの中で最古のIDのうち、最も新しいものを取得
const thresholdId = redisResult.map(ids => ids[0]).sort()[0];
Expand All @@ -75,7 +77,7 @@ export class FanoutTimelineEndpointService {
let noteIds = redisResultIds.filter(id => id >= thresholdId).slice(0, ps.limit);

const oldestNoteId = ascending ? redisResultIds[0] : redisResultIds[redisResultIds.length - 1];
shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0) || (ps.sinceId != null && ps.sinceId < oldestNoteId);
shouldFallbackToDb ||= ps.useDbFallback && (noteIds.length === 0 || ps.sinceId != null && ps.sinceId < oldestNoteId);

if (!shouldFallbackToDb) {
let filter = ps.noteFilter ?? (_note => true);
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/server/api/endpoints/users/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me),
preventEmptyTimelineDbFallback: true,
});

return timeline;
Expand Down

0 comments on commit 1999a5e

Please sign in to comment.