summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-04-08 13:12:49 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-04-08 13:12:49 +0900
commitfa67fb42b1baf616d860c54f6cdf9123fc7ed57a (patch)
treeca492ceed1cda70c33dd20161b06fd69404fd59a /packages/backend/src/server/api
parenttweak MkWindow.vue (diff)
downloadsharkey-fa67fb42b1baf616d860c54f6cdf9123fc7ed57a.tar.gz
sharkey-fa67fb42b1baf616d860c54f6cdf9123fc7ed57a.tar.bz2
sharkey-fa67fb42b1baf616d860c54f6cdf9123fc7ed57a.zip
enhance(backend): Redisにチャンネル投稿がない場合はDBから持ってくるように
Fix #10473
Diffstat (limited to 'packages/backend/src/server/api')
-rw-r--r--packages/backend/src/server/api/endpoints/channels/timeline.ts67
1 files changed, 43 insertions, 24 deletions
diff --git a/packages/backend/src/server/api/endpoints/channels/timeline.ts b/packages/backend/src/server/api/endpoints/channels/timeline.ts
index dfc2a582dc..2556557b24 100644
--- a/packages/backend/src/server/api/endpoints/channels/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/channels/timeline.ts
@@ -1,7 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import Redis from 'ioredis';
import { Endpoint } from '@/server/api/endpoint-base.js';
-import type { ChannelsRepository, NotesRepository } from '@/models/index.js';
+import type { ChannelsRepository, Note, NotesRepository } from '@/models/index.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
@@ -73,6 +73,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
throw new ApiError(meta.errors.noSuchChannel);
}
+ let timeline: Note[] = [];
+
const noteIdsRes = await this.redisClient.xrevrange(
`channelTimeline:${channel.id}`,
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : '+',
@@ -80,34 +82,51 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
'COUNT', ps.limit + 1); // untilIdに指定したものも含まれるため+1
if (noteIdsRes.length === 0) {
- return [];
- }
+ //#region Construct query
+ const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
+ .andWhere('note.channelId = :channelId', { channelId: channel.id })
+ .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 noteIds = noteIdsRes.map(x => x[1][1]).filter(x => x !== ps.untilId);
+ if (me) {
+ this.queryService.generateMutedUserQuery(query, me);
+ this.queryService.generateMutedNoteQuery(query, me);
+ this.queryService.generateBlockedUserQuery(query, me);
+ }
+ //#endregion
- if (noteIds.length === 0) {
- return [];
- }
+ timeline = await query.take(ps.limit).getMany();
+ } else {
+ const noteIds = noteIdsRes.map(x => x[1][1]).filter(x => x !== ps.untilId);
- //#region Construct query
- 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');
+ if (noteIds.length === 0) {
+ return [];
+ }
- if (me) {
- this.queryService.generateMutedUserQuery(query, me);
- this.queryService.generateMutedNoteQuery(query, me);
- this.queryService.generateBlockedUserQuery(query, me);
- }
- //#endregion
+ //#region Construct query
+ 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');
+
+ if (me) {
+ this.queryService.generateMutedUserQuery(query, me);
+ this.queryService.generateMutedNoteQuery(query, me);
+ this.queryService.generateBlockedUserQuery(query, me);
+ }
+ //#endregion
- const timeline = await query.getMany();
- timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ timeline = await query.getMany();
+ timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
if (me) this.activeUsersChart.read(me);