-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mongo] optimizations #859
Changes from 1 commit
79ba25b
18f86f1
07bd2d1
b9ecdc1
c862458
458b89e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -95,9 +95,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => { | |||||||||||
}) | ||||||||||||
.toArray(); | ||||||||||||
|
||||||||||||
const assistantIds = conversations | ||||||||||||
.map((conv) => conv.assistantId) | ||||||||||||
.filter((el) => !!el) as ObjectId[]; | ||||||||||||
const assistantIds = settings?.assistants?.map((assistantId) => assistantId) ?? []; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with this change, it is possible to re-use the results from cc: @nsarrazin is this change good? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the change is: getting all the assistants of a user, instead of only ones user has conversation with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you elaborate on what's expected behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need all assistants for conversations in order to compute their avatarHash below: avatarHash:
conv.assistantId &&
assistants.find((a) => a._id.toString() === conv.assistantId?.toString())?.avatar, If a user removes an assistant from their settings, with this PR, the avatar of the assitant won't show up in the conversation list next to the conversation title. Eg julien's avatar wouldn't show here: (if I removed him in my settings) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can still do this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handled in 07bd2d1 |
||||||||||||
|
||||||||||||
const assistants = await collections.assistants.find({ _id: { $in: assistantIds } }).toArray(); | ||||||||||||
|
||||||||||||
|
@@ -157,6 +155,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, | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe another optimization to do?
There was a problem hiding this comment.
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