Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
createdAt: 1,
assistantId: 1,
})
.limit(300)
.toArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.toArray();
.limit(100)
.toArray();

Maybe another optimization to do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied the change. Will implement pagination for conversation in a subsequent PR


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();

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 2 additions & 13 deletions src/routes/settings/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;