diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index ceaedaab81f..074875a3b7c 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -73,11 +73,13 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => { createdAt: 1, assistantId: 1, }) + .limit(300) .toArray(); - const assistantIds = conversations - .map((conv) => conv.assistantId) - .filter((el) => !!el) as ObjectId[]; + const assistantIds = [ + ...(settings?.assistants?.map((assistantId) => assistantId) ?? []), + ...(conversations.map((conv) => conv.assistantId).filter((el) => !!el) as ObjectId[]), + ]; const assistants = await collections.assistants.find({ _id: { $in: assistantIds } }).toArray(); @@ -160,6 +162,12 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => { unlisted: model.unlisted, })), oldModels, + assistants: assistants.map((el) => ({ + ...el, + _id: el._id.toString(), + createdById: undefined, + createdByMe: el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(), + })), user: locals.user && { id: locals.user._id.toString(), username: locals.user.username, diff --git a/src/routes/settings/+layout.server.ts b/src/routes/settings/+layout.server.ts index 63daa415ad8..140b1a7e149 100644 --- a/src/routes/settings/+layout.server.ts +++ b/src/routes/settings/+layout.server.ts @@ -1,17 +1,9 @@ import { collections } from "$lib/server/database"; -import { ObjectId } from "mongodb"; import type { LayoutServerLoad } from "./$types"; import type { Report } from "$lib/types/Report"; export const load = (async ({ locals, parent }) => { - const { settings } = await parent(); - - // find assistants matching the settings assistants - const assistants = await collections.assistants - .find({ - _id: { $in: settings.assistants.map((el) => new ObjectId(el)) }, - }) - .toArray(); + const { assistants } = await parent(); let reportsByUser: string[] = []; const createdBy = locals.user?._id ?? locals.sessionId; @@ -25,10 +17,7 @@ export const load = (async ({ locals, parent }) => { return { assistants: assistants.map((el) => ({ ...el, - _id: el._id.toString(), - createdById: undefined, - createdByMe: el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(), - reported: reportsByUser.includes(el._id.toString()), + reported: reportsByUser.includes(el._id), })), }; }) satisfies LayoutServerLoad;