chore(endpoints/user-list-timeline): FanoutTimelineEndpointServiceで再実装
This commit is contained in:
parent
816b8b936b
commit
ef435138c7
|
|
@ -17,6 +17,7 @@ import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
|
||||||
import { QueryService } from '@/core/QueryService.js';
|
import { QueryService } from '@/core/QueryService.js';
|
||||||
import { MiLocalUser } from '@/models/User.js';
|
import { MiLocalUser } from '@/models/User.js';
|
||||||
import { MetaService } from '@/core/MetaService.js';
|
import { MetaService } from '@/core/MetaService.js';
|
||||||
|
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
|
@ -82,6 +83,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private cacheService: CacheService,
|
private cacheService: CacheService,
|
||||||
private idService: IdService,
|
private idService: IdService,
|
||||||
private fanoutTimelineService: FanoutTimelineService,
|
private fanoutTimelineService: FanoutTimelineService,
|
||||||
|
private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
|
||||||
private queryService: QueryService,
|
private queryService: QueryService,
|
||||||
private metaService: MetaService,
|
private metaService: MetaService,
|
||||||
) {
|
) {
|
||||||
|
|
@ -101,7 +103,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
const serverSettings = await this.metaService.fetch();
|
const serverSettings = await this.metaService.fetch();
|
||||||
|
|
||||||
if (!serverSettings.enableFanoutTimeline) {
|
if (!serverSettings.enableFanoutTimeline) {
|
||||||
return await this.getFromDb(list, {
|
const timeline = await this.getFromDb(list, {
|
||||||
untilId,
|
untilId,
|
||||||
sinceId,
|
sinceId,
|
||||||
limit: ps.limit,
|
limit: ps.limit,
|
||||||
|
|
@ -111,6 +113,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
withFiles: ps.withFiles,
|
withFiles: ps.withFiles,
|
||||||
withRenotes: ps.withRenotes,
|
withRenotes: ps.withRenotes,
|
||||||
}, me);
|
}, me);
|
||||||
|
|
||||||
|
this.activeUsersChart.read(me);
|
||||||
|
|
||||||
|
await this.noteEntityService.packMany(timeline, me);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [
|
const [
|
||||||
|
|
@ -123,24 +129,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.cacheService.userBlockedCache.fetch(me.id),
|
this.cacheService.userBlockedCache.fetch(me.id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let noteIds = await this.fanoutTimelineService.get(ps.withFiles ? `userListTimelineWithFiles:${list.id}` : `userListTimeline:${list.id}`, untilId, sinceId);
|
const timeline = await this.fanoutTimelineEndpointService.timeline({
|
||||||
noteIds = noteIds.slice(0, ps.limit);
|
untilId,
|
||||||
|
sinceId,
|
||||||
let redisTimeline: MiNote[] = [];
|
limit: ps.limit,
|
||||||
|
me,
|
||||||
if (noteIds.length > 0) {
|
redisTimelines: ps.withFiles ? [`userListTimelineWithFiles:${list.id}`] : [`userListTimeline:${list.id}`],
|
||||||
const query = this.notesRepository.createQueryBuilder('note')
|
noteFilter: 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 => {
|
|
||||||
if (note.userId === me.id) {
|
if (note.userId === me.id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -154,30 +149,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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) {
|
return timeline;
|
||||||
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 [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,10 +258,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
const timeline = await query.limit(ps.limit).getMany();
|
return await query.limit(ps.limit).getMany();
|
||||||
|
|
||||||
this.activeUsersChart.read(me);
|
|
||||||
|
|
||||||
return await this.noteEntityService.packMany(timeline, me);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue