-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Reduce amount of stuff we fetch on /persona
#4988
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
PR Summary
Optimizes the persona/assistants API performance by introducing a MinimalPersonaSnapshot type to reduce payload size and database load time.
- Introduced
PersonaLoadType
enum in backend to control granularity of data loading (NONE, MINIMAL, FULL) inbackend/onyx/db/persona.py
- Replaced full
Persona
type withMinimalPersonaSnapshot
across frontend components, significantly reducing data transfer payload - Switched from
selectinload
tojoinedload
in persona queries for better SQL query performance inbackend/onyx/db/persona.py
- Consolidated assistant data fetching into new
useAdminPersonas
hook with SWR caching inweb/src/app/admin/assistants/hooks.ts
- Simplified persona retrieval logic by removing unnecessary user files/folders checks in
web/src/app/chat/lib.tsx
48 files reviewed, 14 comments
Edit PR Review Bot Settings | Greptile
|
||
let filteredAssistants = filterAssistants( | ||
assistants, | ||
hasAnyConnectors, | ||
hasImageCompatibleModel | ||
); | ||
let filteredAssistants = filterAssistants(assistants); |
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.
logic: filterAssistants is called without previously required params. Make sure this function has been updated to handle this change in its implementation
.map((id) => assistants.find((assistant) => assistant.id === id)) | ||
.filter((assistant): assistant is Persona => assistant !== undefined); | ||
.filter( | ||
(assistant): assistant is MinimalPersonaSnapshot => | ||
assistant !== undefined | ||
); |
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.
style: Consider extracting this common pinned assistants filter logic into a shared utility function since it's duplicated in the useEffect
const reorderedPersonas = orderedPersonaIds.map( | ||
(id) => personas.find((persona) => persona.id.toString() === id)! | ||
); |
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.
logic: Add null check here. The !
operator assumes the find will always succeed, but this could throw if the ID doesn't exist
const reorderedPersonas = orderedPersonaIds.map( | |
(id) => personas.find((persona) => persona.id.toString() === id)! | |
); | |
const reorderedPersonas = orderedPersonaIds.map((id) => { | |
const persona = personas.find((p) => p.id.toString() === id); | |
if (!persona) { | |
throw new Error(`Persona with id ${id} not found`); | |
} | |
return persona; | |
}); |
error?.info?.message || | ||
error?.info?.detail || | ||
"An unknown error occurred" |
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.
style: Consider using more specific error types instead of optional chaining through generic error object
owner=( | ||
MinimalUserSnapshot(id=persona.user.id, email=persona.user.email) | ||
if persona.user | ||
else None | ||
), |
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.
logic: persona.user is accessed before the null check. Move the persona.user.id and email access inside the parentheses to prevent potential NullPointerException.
owner=( | |
MinimalUserSnapshot(id=persona.user.id, email=persona.user.email) | |
if persona.user | |
else None | |
), | |
owner=( | |
MinimalUserSnapshot(id=user.id, email=user.email) | |
if (user := persona.user) | |
else None | |
), |
const url = buildApiPath("/api/admin/persona", { | ||
include_deleted: includeDeleted.toString(), | ||
get_editable: getEditable.toString(), | ||
}); |
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.
style: Converting booleans to strings manually is error-prone. Consider adding URLSearchParams utility
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.
some nits and efficiency things that might help
# Used for filtering | ||
joinedload(Persona.labels), | ||
# only show document sets in the UI that the assistant has access to | ||
joinedload(Persona.document_sets), |
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.
Probably should include these from below since they get used in the minimalsnapshot:
.joinedload(DocumentSet.connector_credential_pairs)
.joinedload(ConnectorCredentialPair.connector),
joinedload(Persona.document_sets)
.joinedload(DocumentSet.connector_credential_pairs)
.joinedload(ConnectorCredentialPair.credential),
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.
Also these:
joinedload(Persona.document_sets).joinedload(DocumentSet.users),
joinedload(Persona.document_sets).joinedload(DocumentSet.groups),
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.
Also on user
@@ -119,7 +120,7 @@ export function PersonasTable() { | |||
if (personaToDelete) { | |||
const response = await deletePersona(personaToDelete.id); | |||
if (response.ok) { | |||
await refreshAssistants(); | |||
refreshPersonas(); |
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.
potential greptile w?
let filteredAssistants = assistants.filter( | ||
(assistant) => assistant.is_visible | ||
); | ||
|
||
if (!hasAnyConnectors) { |
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.
don't need these anymore?
e1e3a01
to
47ea4a0
Compare
Description
Fixes https://linear.app/danswer/issue/DAN-2161/improve-latency-of-persona-endpoint
How Has This Been Tested?
Tested persona / assistant functionality locally
Backporting (check the box to trigger backport action)
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.