diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts index 5736aad5f9c0d27824549d9de4c61cc0b2797735..62b2119a2cd7036c5c5be73ff0c2433d124370e4 100644 --- a/packages/backend/src/server/api/endpoints/users/notes.ts +++ b/packages/backend/src/server/api/endpoints/users/notes.ts @@ -144,45 +144,47 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- timeline.sort((a, b) => a.id > b.id ? -1 : 1); - return await this.noteEntityService.packMany(timeline, me); - } else { - // fallback to database - - //#region Construct query - const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) - .andWhere('note.userId = :userId', { userId: ps.userId }) - .innerJoinAndSelect('note.user', 'user') - .leftJoinAndSelect('note.reply', 'reply') - .leftJoinAndSelect('note.renote', 'renote') - .leftJoinAndSelect('note.channel', 'channel') - .leftJoinAndSelect('reply.user', 'replyUser') - .leftJoinAndSelect('renote.user', 'renoteUser'); - - if (!ps.withChannelNotes) { - query.andWhere('note.channelId IS NULL'); + if (timeline.length > 0) { + return await this.noteEntityService.packMany(timeline, me); } + } - this.queryService.generateVisibilityQuery(query, me); + // fallback to database - if (ps.withFiles) { - query.andWhere('note.fileIds != \'{}\''); - } + //#region Construct query + const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) + .andWhere('note.userId = :userId', { userId: ps.userId }) + .innerJoinAndSelect('note.user', 'user') + .leftJoinAndSelect('note.reply', 'reply') + .leftJoinAndSelect('note.renote', 'renote') + .leftJoinAndSelect('note.channel', 'channel') + .leftJoinAndSelect('reply.user', 'replyUser') + .leftJoinAndSelect('renote.user', 'renoteUser'); - if (ps.includeMyRenotes === false) { - query.andWhere(new Brackets(qb => { - qb.orWhere('note.userId != :userId', { userId: ps.userId }); - qb.orWhere('note.renoteId IS NULL'); - qb.orWhere('note.text IS NOT NULL'); - qb.orWhere('note.fileIds != \'{}\''); - qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); - })); - } - //#endregion + if (!ps.withChannelNotes) { + query.andWhere('note.channelId IS NULL'); + } - const timeline = await query.limit(ps.limit).getMany(); + this.queryService.generateVisibilityQuery(query, me); - return await this.noteEntityService.packMany(timeline, me); + if (ps.withFiles) { + query.andWhere('note.fileIds != \'{}\''); } + + if (ps.includeMyRenotes === false) { + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :userId', { userId: ps.userId }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); + } + //#endregion + + const timeline = await query.limit(ps.limit).getMany(); + + return await this.noteEntityService.packMany(timeline, me); }); } }