summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-11-16 10:20:57 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-11-16 10:20:57 +0900
commit9d78a1a8b3c17e7f91b85e68d03502c068dd6c97 (patch)
treed8ccfeedc0f964a8636fcb76e5cb903448306ca1 /packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
parentUpdate CHANGELOG.md (diff)
downloadsharkey-9d78a1a8b3c17e7f91b85e68d03502c068dd6c97.tar.gz
sharkey-9d78a1a8b3c17e7f91b85e68d03502c068dd6c97.tar.bz2
sharkey-9d78a1a8b3c17e7f91b85e68d03502c068dd6c97.zip
enhance(backend): make ftt db fallback configurable
Diffstat (limited to 'packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts')
-rw-r--r--packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts162
1 files changed, 83 insertions, 79 deletions
diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
index 19c24a78f4..408c2fa371 100644
--- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
@@ -93,87 +93,100 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const serverSettings = await this.metaService.fetch();
- if (serverSettings.enableFanoutTimeline) {
- const [
- userIdsWhoMeMuting,
- userIdsWhoMeMutingRenotes,
- userIdsWhoBlockingMe,
- ] = await Promise.all([
- this.cacheService.userMutingsCache.fetch(me.id),
- this.cacheService.renoteMutingsCache.fetch(me.id),
- this.cacheService.userBlockedCache.fetch(me.id),
- ]);
+ if (!serverSettings.enableFanoutTimeline) {
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ }, me);
+ }
- let noteIds: string[];
- let shouldFallbackToDb = false;
+ const [
+ userIdsWhoMeMuting,
+ userIdsWhoMeMutingRenotes,
+ userIdsWhoBlockingMe,
+ ] = await Promise.all([
+ this.cacheService.userMutingsCache.fetch(me.id),
+ this.cacheService.renoteMutingsCache.fetch(me.id),
+ this.cacheService.userBlockedCache.fetch(me.id),
+ ]);
- if (ps.withFiles) {
- const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
- `homeTimelineWithFiles:${me.id}`,
- 'localTimelineWithFiles',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
- } else if (ps.withReplies) {
- const [htlNoteIds, ltlNoteIds, ltlReplyNoteIds] = await this.funoutTimelineService.getMulti([
- `homeTimeline:${me.id}`,
- 'localTimeline',
- 'localTimelineWithReplies',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds, ...ltlReplyNoteIds]));
- } else {
- const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
- `homeTimeline:${me.id}`,
- 'localTimeline',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
- shouldFallbackToDb = htlNoteIds.length === 0;
- }
+ let noteIds: string[];
+ let shouldFallbackToDb = false;
- noteIds.sort((a, b) => a > b ? -1 : 1);
- noteIds = noteIds.slice(0, ps.limit);
+ if (ps.withFiles) {
+ const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
+ `homeTimelineWithFiles:${me.id}`,
+ 'localTimelineWithFiles',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
+ } else if (ps.withReplies) {
+ const [htlNoteIds, ltlNoteIds, ltlReplyNoteIds] = await this.funoutTimelineService.getMulti([
+ `homeTimeline:${me.id}`,
+ 'localTimeline',
+ 'localTimelineWithReplies',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds, ...ltlReplyNoteIds]));
+ } else {
+ const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
+ `homeTimeline:${me.id}`,
+ 'localTimeline',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
+ shouldFallbackToDb = htlNoteIds.length === 0;
+ }
- shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0);
+ noteIds.sort((a, b) => a > b ? -1 : 1);
+ noteIds = noteIds.slice(0, ps.limit);
- let redisTimeline: MiNote[] = [];
+ shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0);
- if (!shouldFallbackToDb) {
- 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');
+ let redisTimeline: MiNote[] = [];
- redisTimeline = await query.getMany();
+ if (!shouldFallbackToDb) {
+ 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');
- redisTimeline = redisTimeline.filter(note => {
- if (note.userId === me.id) {
- return true;
- }
- if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
- if (isUserRelated(note, userIdsWhoMeMuting)) return false;
- if (note.renoteId) {
- if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
- if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
- if (ps.withRenotes === false) return false;
- }
- }
+ redisTimeline = await query.getMany();
+ redisTimeline = redisTimeline.filter(note => {
+ if (note.userId === me.id) {
return true;
- });
+ }
+ if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
+ if (isUserRelated(note, userIdsWhoMeMuting)) return false;
+ if (note.renoteId) {
+ if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
+ if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
+ if (ps.withRenotes === false) return false;
+ }
+ }
- redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
- }
+ return true;
+ });
- if (redisTimeline.length > 0) {
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
- return await this.noteEntityService.packMany(redisTimeline, me);
- } else { // fallback to db
+ if (redisTimeline.length > 0) {
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+
+ return await this.noteEntityService.packMany(redisTimeline, me);
+ } else {
+ if (serverSettings.enableFanoutTimelineDbFallback) { // fallback to db
return await this.getFromDb({
untilId,
sinceId,
@@ -184,18 +197,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withReplies: ps.withReplies,
}, me);
+ } else {
+ return [];
}
- } else {
- return await this.getFromDb({
- untilId,
- sinceId,
- limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
- withFiles: ps.withFiles,
- withReplies: ps.withReplies,
- }, me);
}
});
}