perf: fetch following ids before any requests
This commit is contained in:
parent
091f740a29
commit
4f19c1c3c0
2 changed files with 29 additions and 31 deletions
|
@ -277,19 +277,18 @@ export const NoteRepository = db.getRepository(Note).extend({
|
||||||
emojis: noteEmoji,
|
emojis: noteEmoji,
|
||||||
tags: note.tags.length > 0 ? note.tags : undefined,
|
tags: note.tags.length > 0 ? note.tags : undefined,
|
||||||
fileIds: note.fileIds,
|
fileIds: note.fileIds,
|
||||||
files:
|
files: scyllaClient
|
||||||
scyllaClient && foundScyllaNote
|
? (note as ScyllaNote).files.map((file) => ({
|
||||||
? (note as ScyllaNote).files.map((file) => ({
|
...file,
|
||||||
...file,
|
createdAt: file.createdAt.toISOString(),
|
||||||
createdAt: file.createdAt.toISOString(),
|
properties: {
|
||||||
properties: {
|
width: file.width ?? undefined,
|
||||||
width: file.width ?? undefined,
|
height: file.height ?? undefined,
|
||||||
height: file.height ?? undefined,
|
},
|
||||||
},
|
userId: null,
|
||||||
userId: null,
|
folderId: null,
|
||||||
folderId: null,
|
}))
|
||||||
}))
|
: DriveFiles.packMany(note.fileIds),
|
||||||
: DriveFiles.packMany(note.fileIds),
|
|
||||||
replyId: note.replyId,
|
replyId: note.replyId,
|
||||||
renoteId: note.renoteId,
|
renoteId: note.renoteId,
|
||||||
channelId: note.channelId || undefined,
|
channelId: note.channelId || undefined,
|
||||||
|
|
|
@ -61,27 +61,27 @@ export const paramDef = {
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
export default define(meta, paramDef, async (ps, user) => {
|
||||||
const note = await getNote(ps.noteId, user).catch((err) => {
|
let followingUserIds: string[] = [];
|
||||||
|
if (user) {
|
||||||
|
followingUserIds = await LocalFollowingsCache.init(user.id).then((cache) =>
|
||||||
|
cache.getAll(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const note = await getNote(ps.noteId, user, followingUserIds).catch((err) => {
|
||||||
if (err.id === "9725d0ce-ba28-4dde-95a7-2cbb2c15de24")
|
if (err.id === "9725d0ce-ba28-4dde-95a7-2cbb2c15de24")
|
||||||
throw new ApiError(meta.errors.noSuchNote);
|
throw new ApiError(meta.errors.noSuchNote);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scyllaClient) {
|
if (scyllaClient) {
|
||||||
let [
|
let [mutedUserIds, mutedInstances, blockerIds]: string[][] = [];
|
||||||
followingUserIds,
|
|
||||||
mutedUserIds,
|
|
||||||
mutedInstances,
|
|
||||||
blockerIds,
|
|
||||||
]: string[][] = [];
|
|
||||||
if (user) {
|
if (user) {
|
||||||
[followingUserIds, mutedUserIds, mutedInstances, blockerIds] =
|
[mutedUserIds, mutedInstances, blockerIds] = await Promise.all([
|
||||||
await Promise.all([
|
UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
|
||||||
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()),
|
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
|
||||||
UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
|
UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
|
||||||
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
|
]);
|
||||||
UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const filter = async (notes: ScyllaNote[]) => {
|
const filter = async (notes: ScyllaNote[]) => {
|
||||||
|
@ -105,10 +105,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
const foundPacked = [];
|
const foundPacked = [];
|
||||||
let untilDate: number | undefined;
|
let untilDate: number | undefined;
|
||||||
while (foundPacked.length < ps.limit) {
|
while (foundPacked.length < ps.limit) {
|
||||||
const foundNotes = (await execNotePaginationQuery({...ps, untilDate}, filter, 1)).slice(
|
const foundNotes = (
|
||||||
0,
|
await execNotePaginationQuery({ ...ps, untilDate }, filter, 1)
|
||||||
ps.limit * 1.5,
|
).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
|
||||||
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
|
|
||||||
foundPacked.push(
|
foundPacked.push(
|
||||||
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
|
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue