summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authoranatawa12 <anatawa12@icloud.com>2023-12-02 18:25:07 +0900
committerGitHub <noreply@github.com>2023-12-02 18:25:07 +0900
commita631b976c99a4b3977079a4bafc8a7b7de0bf269 (patch)
tree2de46905d201657061e6deaf3db1fdd2d44b0a3c /packages/backend/src/server/api/endpoints/notes
parentfix(frontend): MFM ruby nyaize (#12362) (diff)
downloadsharkey-a631b976c99a4b3977079a4bafc8a7b7de0bf269.tar.gz
sharkey-a631b976c99a4b3977079a4bafc8a7b7de0bf269.tar.bz2
sharkey-a631b976c99a4b3977079a4bafc8a7b7de0bf269.zip
Refine fanout timeline (#12507)
* chore(endpoints/hybrid-timeline): don't pack inside getFromDb * chore(endpoints/hybrid-timeline): Redisから取得する部分のうちSTLに依存しなそうなところを別のServiceに切り出し * chore(endpoints/local-timeline): FanoutTimelineEndpointServiceで再実装 * chore(endpoints/channels/timeline): FanoutTimelineEndpointServiceで再実装 * chore(endpoints/timeline): FanoutTimelineEndpointServiceで再実装 * chore(endpoints/user-list-timeline): FanoutTimelineEndpointServiceで再実装 * chore(endpoints/users/notes): FanoutTimelineEndpointServiceで再実装 * chore: add useDbFallback to FanoutTimelineEndpointService.timeline and always true for channel / user note list * style: fix lint error * chore: split logic to multiple functions * chore: implement redis fallback * chore: 成功率を上げる * fix: db fallback not working * feat: allowPartial * chore(frontend): set allowPartial * chore(backend): remove fallbackIfEmpty HTL will never be purged so it's no longer required * fix: missing allowPartial in channel timeline * fix: type of timelineConfig in hybrid-timeline --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/server/api/endpoints/notes')
-rw-r--r--packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts110
-rw-r--r--packages/backend/src/server/api/endpoints/notes/local-timeline.ts103
-rw-r--r--packages/backend/src/server/api/endpoints/notes/timeline.ts91
-rw-r--r--packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts78
4 files changed, 149 insertions, 233 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 372199844d..820692626c 100644
--- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
@@ -5,7 +5,7 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
-import type { NotesRepository, FollowingsRepository, MiNote, ChannelFollowingsRepository } from '@/models/_.js';
+import type { NotesRepository, ChannelFollowingsRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
@@ -19,6 +19,7 @@ import { QueryService } from '@/core/QueryService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { MetaService } from '@/core/MetaService.js';
import { MiLocalUser } from '@/models/User.js';
+import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -53,6 +54,7 @@ export const paramDef = {
untilId: { type: 'string', format: 'misskey:id' },
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
+ allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
includeMyRenotes: { type: 'boolean', default: true },
includeRenotedMyNotes: { type: 'boolean', default: true },
includeLocalRenotes: { type: 'boolean', default: true },
@@ -77,10 +79,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private activeUsersChart: ActiveUsersChart,
private idService: IdService,
private cacheService: CacheService,
- private fanoutTimelineService: FanoutTimelineService,
private queryService: QueryService,
private userFollowingService: UserFollowingService,
private metaService: MetaService,
+ private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -94,7 +96,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const serverSettings = await this.metaService.fetch();
if (!serverSettings.enableFanoutTimeline) {
- return await this.getFromDb({
+ const timeline = await this.getFromDb({
untilId,
sinceId,
limit: ps.limit,
@@ -104,6 +106,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withReplies: ps.withReplies,
}, me);
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+
+ return await this.noteEntityService.packMany(timeline, me);
}
const [
@@ -116,51 +124,34 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.cacheService.userBlockedCache.fetch(me.id),
]);
- let noteIds: string[];
- let shouldFallbackToDb = false;
+ let timelineConfig: string[];
if (ps.withFiles) {
- const [htlNoteIds, ltlNoteIds] = await this.fanoutTimelineService.getMulti([
+ timelineConfig = [
`homeTimelineWithFiles:${me.id}`,
'localTimelineWithFiles',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
+ ];
} else if (ps.withReplies) {
- const [htlNoteIds, ltlNoteIds, ltlReplyNoteIds] = await this.fanoutTimelineService.getMulti([
+ timelineConfig = [
`homeTimeline:${me.id}`,
'localTimeline',
'localTimelineWithReplies',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds, ...ltlReplyNoteIds]));
+ ];
} else {
- const [htlNoteIds, ltlNoteIds] = await this.fanoutTimelineService.getMulti([
+ timelineConfig = [
`homeTimeline:${me.id}`,
'localTimeline',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
- shouldFallbackToDb = htlNoteIds.length === 0;
+ ];
}
- noteIds.sort((a, b) => a > b ? -1 : 1);
- noteIds = noteIds.slice(0, ps.limit);
-
- shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0);
-
- let redisTimeline: MiNote[] = [];
-
- 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 = await query.getMany();
-
- redisTimeline = redisTimeline.filter(note => {
+ const redisTimeline = await this.fanoutTimelineEndpointService.timeline({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ allowPartial: ps.allowPartial,
+ redisTimelines: timelineConfig,
+ useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
+ noteFilter: (note) => {
if (note.userId === me.id) {
return true;
}
@@ -174,33 +165,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
return true;
- });
-
- redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
- }
+ },
+ dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({
+ untilId,
+ sinceId,
+ limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ }, me),
+ });
- if (redisTimeline.length > 0) {
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ 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,
- limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
- withFiles: ps.withFiles,
- withReplies: ps.withReplies,
- }, me);
- } else {
- return [];
- }
- }
+ return redisTimeline;
});
}
@@ -301,12 +283,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
//#endregion
- const timeline = await query.limit(ps.limit).getMany();
-
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
-
- return await this.noteEntityService.packMany(timeline, me);
+ return await query.limit(ps.limit).getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
index 8867070055..97b05016ec 100644
--- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
@@ -14,10 +14,10 @@ import { RoleService } from '@/core/RoleService.js';
import { IdService } from '@/core/IdService.js';
import { CacheService } from '@/core/CacheService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
-import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { QueryService } from '@/core/QueryService.js';
import { MetaService } from '@/core/MetaService.js';
import { MiLocalUser } from '@/models/User.js';
+import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -51,6 +51,7 @@ export const paramDef = {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
+ allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
},
@@ -68,7 +69,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private activeUsersChart: ActiveUsersChart,
private idService: IdService,
private cacheService: CacheService,
- private fanoutTimelineService: FanoutTimelineService,
+ private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
private queryService: QueryService,
private metaService: MetaService,
) {
@@ -84,13 +85,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const serverSettings = await this.metaService.fetch();
if (!serverSettings.enableFanoutTimeline) {
- return await this.getFromDb({
+ const timeline = await this.getFromDb({
untilId,
sinceId,
limit: ps.limit,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
}, me);
+
+ process.nextTick(() => {
+ if (me) {
+ this.activeUsersChart.read(me);
+ }
+ });
+
+ return await this.noteEntityService.packMany(timeline, me);
}
const [
@@ -103,36 +112,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.cacheService.userBlockedCache.fetch(me.id),
]) : [new Set<string>(), new Set<string>(), new Set<string>()];
- let noteIds: string[];
-
- if (ps.withFiles) {
- noteIds = await this.fanoutTimelineService.get('localTimelineWithFiles', untilId, sinceId);
- } else {
- const [nonReplyNoteIds, replyNoteIds] = await this.fanoutTimelineService.getMulti([
- 'localTimeline',
- 'localTimelineWithReplies',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...nonReplyNoteIds, ...replyNoteIds]));
- noteIds.sort((a, b) => a > b ? -1 : 1);
- }
-
- noteIds = noteIds.slice(0, ps.limit);
-
- let redisTimeline: MiNote[] = [];
-
- if (noteIds.length > 0) {
- 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 = await query.getMany();
-
- redisTimeline = redisTimeline.filter(note => {
+ const timeline = await this.fanoutTimelineEndpointService.timeline({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ allowPartial: ps.allowPartial,
+ me,
+ useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
+ redisTimelines: ps.withFiles ? ['localTimelineWithFiles'] : ['localTimeline', 'localTimelineWithReplies'],
+ noteFilter: note => {
if (me && (note.userId === me.id)) {
return true;
}
@@ -147,32 +135,23 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
return true;
- });
-
- redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
- }
-
- if (redisTimeline.length > 0) {
- process.nextTick(() => {
- if (me) {
- this.activeUsersChart.read(me);
- }
- });
+ },
+ dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({
+ untilId,
+ sinceId,
+ limit,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ }, me),
+ });
- return await this.noteEntityService.packMany(redisTimeline, me);
- } else {
- if (serverSettings.enableFanoutTimelineDbFallback) { // fallback to db
- return await this.getFromDb({
- untilId,
- sinceId,
- limit: ps.limit,
- withFiles: ps.withFiles,
- withReplies: ps.withReplies,
- }, me);
- } else {
- return [];
+ process.nextTick(() => {
+ if (me) {
+ this.activeUsersChart.read(me);
}
- }
+ });
+
+ return timeline;
});
}
@@ -213,14 +192,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
}
- const timeline = await query.limit(ps.limit).getMany();
-
- process.nextTick(() => {
- if (me) {
- this.activeUsersChart.read(me);
- }
- });
-
- return await this.noteEntityService.packMany(timeline, me);
+ return await query.limit(ps.limit).getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts
index 470abe0b14..74d0a6e0c0 100644
--- a/packages/backend/src/server/api/endpoints/notes/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts
@@ -5,7 +5,7 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
-import type { MiNote, NotesRepository, ChannelFollowingsRepository } from '@/models/_.js';
+import type { NotesRepository, ChannelFollowingsRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
@@ -14,10 +14,10 @@ import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js';
import { CacheService } from '@/core/CacheService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
-import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { MiLocalUser } from '@/models/User.js';
import { MetaService } from '@/core/MetaService.js';
+import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
export const meta = {
tags: ['notes'],
@@ -43,6 +43,7 @@ export const paramDef = {
untilId: { type: 'string', format: 'misskey:id' },
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
+ allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
includeMyRenotes: { type: 'boolean', default: true },
includeRenotedMyNotes: { type: 'boolean', default: true },
includeLocalRenotes: { type: 'boolean', default: true },
@@ -65,7 +66,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private activeUsersChart: ActiveUsersChart,
private idService: IdService,
private cacheService: CacheService,
- private fanoutTimelineService: FanoutTimelineService,
+ private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
private userFollowingService: UserFollowingService,
private queryService: QueryService,
private metaService: MetaService,
@@ -77,7 +78,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const serverSettings = await this.metaService.fetch();
if (!serverSettings.enableFanoutTimeline) {
- return await this.getFromDb({
+ const timeline = await this.getFromDb({
untilId,
sinceId,
limit: ps.limit,
@@ -87,6 +88,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me);
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+
+ return await this.noteEntityService.packMany(timeline, me);
}
const [
@@ -101,24 +108,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.cacheService.userBlockedCache.fetch(me.id),
]);
- let noteIds = await this.fanoutTimelineService.get(ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`, untilId, sinceId);
- noteIds = noteIds.slice(0, ps.limit);
-
- let redisTimeline: MiNote[] = [];
-
- if (noteIds.length > 0) {
- 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 = await query.getMany();
-
- redisTimeline = redisTimeline.filter(note => {
+ const timeline = this.fanoutTimelineEndpointService.timeline({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ allowPartial: ps.allowPartial,
+ me,
+ useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
+ redisTimelines: ps.withFiles ? [`homeTimelineWithFiles:${me.id}`] : [`homeTimeline:${me.id}`],
+ noteFilter: note => {
if (note.userId === me.id) {
return true;
}
@@ -135,33 +133,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
return true;
- });
-
- redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
- }
+ },
+ dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({
+ untilId,
+ sinceId,
+ limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withRenotes: ps.withRenotes,
+ }, me),
+ });
- if (redisTimeline.length > 0) {
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ 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,
- limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
- withFiles: ps.withFiles,
- withRenotes: ps.withRenotes,
- }, me);
- } else {
- return [];
- }
- }
+ return timeline;
});
}
@@ -269,12 +258,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
//#endregion
- const timeline = await query.limit(ps.limit).getMany();
-
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
-
- return await this.noteEntityService.packMany(timeline, me);
+ return await query.limit(ps.limit).getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
index 1ac1d37f48..f39cac5c3e 100644
--- a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
@@ -17,6 +17,7 @@ import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { QueryService } from '@/core/QueryService.js';
import { MiLocalUser } from '@/models/User.js';
import { MetaService } from '@/core/MetaService.js';
+import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -52,6 +53,7 @@ export const paramDef = {
untilId: { type: 'string', format: 'misskey:id' },
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
+ allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
includeMyRenotes: { type: 'boolean', default: true },
includeRenotedMyNotes: { type: 'boolean', default: true },
includeLocalRenotes: { type: 'boolean', default: true },
@@ -82,6 +84,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private cacheService: CacheService,
private idService: IdService,
private fanoutTimelineService: FanoutTimelineService,
+ private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
private queryService: QueryService,
private metaService: MetaService,
) {
@@ -101,7 +104,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const serverSettings = await this.metaService.fetch();
if (!serverSettings.enableFanoutTimeline) {
- return await this.getFromDb(list, {
+ const timeline = await this.getFromDb(list, {
untilId,
sinceId,
limit: ps.limit,
@@ -111,6 +114,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me);
+
+ this.activeUsersChart.read(me);
+
+ await this.noteEntityService.packMany(timeline, me);
}
const [
@@ -123,24 +130,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.cacheService.userBlockedCache.fetch(me.id),
]);
- let noteIds = await this.fanoutTimelineService.get(ps.withFiles ? `userListTimelineWithFiles:${list.id}` : `userListTimeline:${list.id}`, untilId, sinceId);
- noteIds = noteIds.slice(0, ps.limit);
-
- let redisTimeline: MiNote[] = [];
-
- if (noteIds.length > 0) {
- 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 = await query.getMany();
-
- redisTimeline = redisTimeline.filter(note => {
+ const timeline = await this.fanoutTimelineEndpointService.timeline({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ allowPartial: ps.allowPartial,
+ me,
+ useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
+ redisTimelines: ps.withFiles ? [`userListTimelineWithFiles:${list.id}`] : [`userListTimeline:${list.id}`],
+ noteFilter: note => {
if (note.userId === me.id) {
return true;
}
@@ -154,30 +152,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
return true;
- });
+ },
+ dbFallback: async (untilId, sinceId, limit) => await this.getFromDb(list, {
+ untilId,
+ sinceId,
+ limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withRenotes: ps.withRenotes,
+ }, me),
+ });
- redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
- }
+ this.activeUsersChart.read(me);
- if (redisTimeline.length > 0) {
- this.activeUsersChart.read(me);
- return await this.noteEntityService.packMany(redisTimeline, me);
- } else {
- if (serverSettings.enableFanoutTimelineDbFallback) { // fallback to db
- return await this.getFromDb(list, {
- untilId,
- sinceId,
- limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
- withFiles: ps.withFiles,
- withRenotes: ps.withRenotes,
- }, me);
- } else {
- return [];
- }
- }
+ return timeline;
});
}
@@ -271,10 +261,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
//#endregion
- const timeline = await query.limit(ps.limit).getMany();
-
- this.activeUsersChart.read(me);
-
- return await this.noteEntityService.packMany(timeline, me);
+ return await query.limit(ps.limit).getMany();
}
}