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,
|
||||
tags: note.tags.length > 0 ? note.tags : undefined,
|
||||
fileIds: note.fileIds,
|
||||
files:
|
||||
scyllaClient && foundScyllaNote
|
||||
? (note as ScyllaNote).files.map((file) => ({
|
||||
...file,
|
||||
createdAt: file.createdAt.toISOString(),
|
||||
properties: {
|
||||
width: file.width ?? undefined,
|
||||
height: file.height ?? undefined,
|
||||
},
|
||||
userId: null,
|
||||
folderId: null,
|
||||
}))
|
||||
: DriveFiles.packMany(note.fileIds),
|
||||
files: scyllaClient
|
||||
? (note as ScyllaNote).files.map((file) => ({
|
||||
...file,
|
||||
createdAt: file.createdAt.toISOString(),
|
||||
properties: {
|
||||
width: file.width ?? undefined,
|
||||
height: file.height ?? undefined,
|
||||
},
|
||||
userId: null,
|
||||
folderId: null,
|
||||
}))
|
||||
: DriveFiles.packMany(note.fileIds),
|
||||
replyId: note.replyId,
|
||||
renoteId: note.renoteId,
|
||||
channelId: note.channelId || undefined,
|
||||
|
|
|
@ -61,27 +61,27 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
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")
|
||||
throw new ApiError(meta.errors.noSuchNote);
|
||||
throw err;
|
||||
});
|
||||
|
||||
if (scyllaClient) {
|
||||
let [
|
||||
followingUserIds,
|
||||
mutedUserIds,
|
||||
mutedInstances,
|
||||
blockerIds,
|
||||
]: string[][] = [];
|
||||
let [mutedUserIds, mutedInstances, blockerIds]: string[][] = [];
|
||||
if (user) {
|
||||
[followingUserIds, mutedUserIds, mutedInstances, blockerIds] =
|
||||
await Promise.all([
|
||||
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()),
|
||||
UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
|
||||
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
|
||||
UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
|
||||
]);
|
||||
[mutedUserIds, mutedInstances, blockerIds] = await Promise.all([
|
||||
UserMutingsCache.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[]) => {
|
||||
|
@ -105,10 +105,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
const foundPacked = [];
|
||||
let untilDate: number | undefined;
|
||||
while (foundPacked.length < ps.limit) {
|
||||
const foundNotes = (await execNotePaginationQuery({...ps, untilDate}, filter, 1)).slice(
|
||||
0,
|
||||
ps.limit * 1.5,
|
||||
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
|
||||
const foundNotes = (
|
||||
await execNotePaginationQuery({ ...ps, untilDate }, filter, 1)
|
||||
).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
|
||||
foundPacked.push(
|
||||
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue