diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-10-07 20:27:35 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-10-07 20:27:35 +0900 |
| commit | 04c8a7077fc60c415b3004a38416c5346e62b9bb (patch) | |
| tree | 1cc4be2365ff54579474277cf6be236b8b83a1d6 /packages/backend/src/server/api/endpoints/users/notes.ts | |
| parent | 2023.10.0-beta.7 (diff) | |
| download | sharkey-04c8a7077fc60c415b3004a38416c5346e62b9bb.tar.gz sharkey-04c8a7077fc60c415b3004a38416c5346e62b9bb.tar.bz2 sharkey-04c8a7077fc60c415b3004a38416c5346e62b9bb.zip | |
fix of 8c684d5391
Diffstat (limited to 'packages/backend/src/server/api/endpoints/users/notes.ts')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/users/notes.ts | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts index becc6debbb..cd05703737 100644 --- a/packages/backend/src/server/api/endpoints/users/notes.ts +++ b/packages/backend/src/server/api/endpoints/users/notes.ts @@ -78,8 +78,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- this.cacheService.userMutingsCache.fetch(me.id), ]) : [new Set<string>()]; - let timeline: MiNote[] = []; - const limit = ps.limit + (ps.untilId ? 1 : 0) + (ps.sinceId ? 1 : 0); // untilIdに指定したものも含まれるため+1 const [noteIdsRes, repliesNoteIdsRes, channelNoteIdsRes] = await Promise.all([ @@ -115,41 +113,40 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- noteIds.sort((a, b) => a > b ? -1 : 1); noteIds = noteIds.slice(0, ps.limit); - if (noteIds.length === 0) { - return []; - } - - const isFollowing = me ? Object.hasOwn(await this.cacheService.userFollowingsCache.fetch(me.id), ps.userId) : false; + if (noteIds.length > 0) { + const isFollowing = me ? Object.hasOwn(await this.cacheService.userFollowingsCache.fetch(me.id), ps.userId) : false; - const query = this.notesRepository.createQueryBuilder('note') - .where('note.id IN (:...noteIds)', { noteIds: noteIds }) - .innerJoinAndSelect('note.user', 'user') - .leftJoinAndSelect('note.reply', 'reply') - .leftJoinAndSelect('note.renote', 'renote') - .leftJoinAndSelect('reply.user', 'replyUser') - .leftJoinAndSelect('renote.user', 'renoteUser') - .leftJoinAndSelect('note.channel', 'channel'); + const query = this.notesRepository.createQueryBuilder('note') + .where('note.id IN (:...noteIds)', { noteIds: noteIds }) + .innerJoinAndSelect('note.user', 'user') + .leftJoinAndSelect('note.reply', 'reply') + .leftJoinAndSelect('note.renote', 'renote') + .leftJoinAndSelect('reply.user', 'replyUser') + .leftJoinAndSelect('renote.user', 'renoteUser') + .leftJoinAndSelect('note.channel', 'channel'); - timeline = await query.getMany(); + let timeline = await query.getMany(); - timeline = timeline.filter(note => { - if (me && isUserRelated(note, userIdsWhoMeMuting, true)) return false; + timeline = timeline.filter(note => { + if (me && isUserRelated(note, userIdsWhoMeMuting, true)) return false; - if (note.renoteId) { - if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { - if (ps.withRenotes === false) return false; + if (note.renoteId) { + if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { + if (ps.withRenotes === false) return false; + } } - } - if (note.visibility === 'followers' && !isFollowing) return false; + if (note.visibility === 'followers' && !isFollowing) return false; + + return true; + }); - return true; - }); + timeline.sort((a, b) => a.id > b.id ? -1 : 1); - timeline.sort((a, b) => a.id > b.id ? -1 : 1); + return await this.noteEntityService.packMany(timeline, me); + } else { + // fallback to database - // fallback to database - if (timeline.length === 0) { //#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 }) @@ -182,10 +179,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- } //#endregion - timeline = await query.limit(ps.limit).getMany(); - } + const timeline = await query.limit(ps.limit).getMany(); - return await this.noteEntityService.packMany(timeline, me); + return await this.noteEntityService.packMany(timeline, me); + } }); } } |