summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/users/notes.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-10-09 16:54:27 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-10-09 16:54:27 +0900
commit0680ea3a78597d95464291d1fb9e703b46b7b1de (patch)
tree380b0486e7aa43130754e8df871533f481a401c5 /packages/backend/src/server/api/endpoints/users/notes.ts
parentfix(backend): TLを途中までしかページネーションできなくな... (diff)
downloadsharkey-0680ea3a78597d95464291d1fb9e703b46b7b1de.tar.gz
sharkey-0680ea3a78597d95464291d1fb9e703b46b7b1de.tar.bz2
sharkey-0680ea3a78597d95464291d1fb9e703b46b7b1de.zip
fix(backend): users/notes で途中までしかページネーションできなくなることがある問題を修正
Diffstat (limited to 'packages/backend/src/server/api/endpoints/users/notes.ts')
-rw-r--r--packages/backend/src/server/api/endpoints/users/notes.ts66
1 files changed, 34 insertions, 32 deletions
diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts
index 5736aad5f9..62b2119a2c 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);
});
}
}