mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-11-01 07:35:57 +09:00
perf(backend): improve hybrid-timeline performance
This commit is contained in:
parent
774bf6a55e
commit
9240db35f3
@ -93,20 +93,23 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||||||
|
|
||||||
const limit = ps.limit + (ps.untilId ? 1 : 0) + (ps.sinceId ? 1 : 0); // untilIdに指定したものも含まれるため+1
|
const limit = ps.limit + (ps.untilId ? 1 : 0) + (ps.sinceId ? 1 : 0); // untilIdに指定したものも含まれるため+1
|
||||||
|
|
||||||
const [htlNoteIds, ltlNoteIds] = await Promise.all([
|
const redisPipeline = this.redisForTimelines.pipeline();
|
||||||
this.redisForTimelines.xrevrange(
|
redisPipeline.xrevrange(
|
||||||
ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`,
|
ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`,
|
||||||
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : ps.untilDate ?? '+',
|
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : ps.untilDate ?? '+',
|
||||||
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : ps.sinceDate ?? '-',
|
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : ps.sinceDate ?? '-',
|
||||||
'COUNT', limit,
|
'COUNT', limit,
|
||||||
).then(res => res.map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId)),
|
);
|
||||||
this.redisForTimelines.xrevrange(
|
redisPipeline.xrevrange(
|
||||||
ps.withFiles ? 'localTimelineWithFiles' : 'localTimeline',
|
ps.withFiles ? 'localTimelineWithFiles' : 'localTimeline',
|
||||||
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : ps.untilDate ?? '+',
|
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : ps.untilDate ?? '+',
|
||||||
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : ps.sinceDate ?? '-',
|
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : ps.sinceDate ?? '-',
|
||||||
'COUNT', limit,
|
'COUNT', limit,
|
||||||
).then(res => res.map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId)),
|
);
|
||||||
]);
|
const [htlNoteIds, ltlNoteIds] = await redisPipeline.exec().then(res => res ? [
|
||||||
|
(res[0][1] as string[][]).map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId),
|
||||||
|
(res[1][1] as string[][]).map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId),
|
||||||
|
] : []);
|
||||||
|
|
||||||
let noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
|
let noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
|
||||||
noteIds.sort((a, b) => a > b ? -1 : 1);
|
noteIds.sort((a, b) => a > b ? -1 : 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user