perf: add option to skip querying skilla
This commit is contained in:
parent
e115fed0db
commit
0da215aa7d
4 changed files with 15 additions and 7 deletions
|
@ -137,8 +137,7 @@ export const NoteRepository = db.getRepository(Note).extend({
|
||||||
Users.findOneByOrFail({ id: meId }),
|
Users.findOneByOrFail({ id: meId }),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!user.host) {
|
if (Users.isLocalUser(user)) {
|
||||||
// user is local
|
|
||||||
const cache = await LocalFollowingsCache.init(meId);
|
const cache = await LocalFollowingsCache.init(meId);
|
||||||
return await cache.isFollowing(note.userId);
|
return await cache.isFollowing(note.userId);
|
||||||
}
|
}
|
||||||
|
@ -169,6 +168,7 @@ export const NoteRepository = db.getRepository(Note).extend({
|
||||||
me?: { id: User["id"] } | null | undefined,
|
me?: { id: User["id"] } | null | undefined,
|
||||||
options?: {
|
options?: {
|
||||||
detail?: boolean;
|
detail?: boolean;
|
||||||
|
scyllaNote?: boolean;
|
||||||
_hint_?: {
|
_hint_?: {
|
||||||
myReactions: Map<Note["id"], NoteReaction | null>;
|
myReactions: Map<Note["id"], NoteReaction | null>;
|
||||||
};
|
};
|
||||||
|
@ -187,7 +187,7 @@ export const NoteRepository = db.getRepository(Note).extend({
|
||||||
const isSrcNote = typeof src === "object";
|
const isSrcNote = typeof src === "object";
|
||||||
|
|
||||||
// Always lookup from ScyllaDB if enabled
|
// Always lookup from ScyllaDB if enabled
|
||||||
if (isSrcNote && !scyllaClient) {
|
if (isSrcNote && (!scyllaClient || options?.scyllaNote)) {
|
||||||
note = src;
|
note = src;
|
||||||
} else {
|
} else {
|
||||||
const noteId = isSrcNote ? src.id : src;
|
const noteId = isSrcNote ? src.id : src;
|
||||||
|
@ -346,6 +346,7 @@ export const NoteRepository = db.getRepository(Note).extend({
|
||||||
me?: { id: User["id"] } | null | undefined,
|
me?: { id: User["id"] } | null | undefined,
|
||||||
options?: {
|
options?: {
|
||||||
detail?: boolean;
|
detail?: boolean;
|
||||||
|
scyllaNote?: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (notes.length === 0) return [];
|
if (notes.length === 0) return [];
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
export async function getNote(
|
export async function getNote(
|
||||||
noteId: Note["id"],
|
noteId: Note["id"],
|
||||||
me: { id: User["id"] } | null,
|
me: { id: User["id"] } | null,
|
||||||
followingIds?: User["id"][]
|
followingIds?: User["id"][],
|
||||||
) {
|
) {
|
||||||
let note: Note | null = null;
|
let note: Note | null = null;
|
||||||
if (scyllaClient) {
|
if (scyllaClient) {
|
||||||
|
@ -32,7 +32,10 @@ export async function getNote(
|
||||||
note = filtered[0];
|
note = filtered[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// Fallback to Postgres
|
||||||
|
if (!note) {
|
||||||
const query = Notes.createQueryBuilder("note").where("note.id = :id", {
|
const query = Notes.createQueryBuilder("note").where("note.id = :id", {
|
||||||
id: noteId,
|
id: noteId,
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,7 +67,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const foundNotes = await execTimelineQuery(ps, filter);
|
const foundNotes = await execTimelineQuery(ps, filter);
|
||||||
return await Notes.packMany(foundNotes.slice(0, ps.limit), user);
|
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
|
||||||
|
scyllaNote: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = makePaginationQuery(
|
const query = makePaginationQuery(
|
||||||
|
|
|
@ -90,7 +90,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const foundNotes = await execTimelineQuery(ps, filter);
|
const foundNotes = await execTimelineQuery(ps, filter);
|
||||||
return await Notes.packMany(foundNotes.slice(0, ps.limit), user);
|
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
|
||||||
|
scyllaNote: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasFollowing = await followingsCache.hasFollowing();
|
const hasFollowing = await followingsCache.hasFollowing();
|
||||||
|
|
Loading…
Reference in a new issue