From 5004f6ec185667774409c77de079d32562f13624 Mon Sep 17 00:00:00 2001 From: yuriha-chan Date: Fri, 6 Oct 2023 15:51:31 +0900 Subject: [PATCH] Fallback to Postgres wip --- .../server/api/endpoints/notes/timeline.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index 7442356978fc..834cf632e8a8 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -89,7 +89,29 @@ export default class extends Endpoint { // eslint- 'COUNT', limit); } - const noteIds = noteIdsRes.map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId); + let noteIds = noteIdsRes.map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId); + + // fallback to postgres + if (noteIds.length < limit) { + const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note.id'), + ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate); + if (followings.length > 0) { + const meOrFolloweeIds = [me.id, ...followings]; + query.andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds }); + } else { + query.andWhere('note.userId = :meId', { meId: me.id }); + } + + this.queryService.generateChannelQuery(query, me); + this.queryService.generateRepliesQuery(query, ps.withReplies, me); + this.queryService.generateVisibilityQuery(query, me); + this.queryService.generateMutedUserQuery(query, me); + this.queryService.generateMutedNoteQuery(query, me); + this.queryService.generateBlockedUserQuery(query, me); + this.queryService.generateMutedUserRenotesQueryForNotes(query, me); + + noteIds = noteIds.concat(await query.limit(limit - noteIds.length).getMany()); + } if (noteIds.length === 0) { return [];