Skip to content

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

Merged
merged 10 commits into from
Jul 12, 2025
Merged

Conversation

Weves
Copy link
Contributor

@Weves Weves commented Jul 4, 2025

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.

  • This PR should be backported (make sure to check that the backport attempt succeeds)
  • [Optional] Override Linear Check

Copy link

vercel bot commented Jul 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
internal-search ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2025 6:36pm

@Weves Weves changed the title claude stuff Reduce amount of stuff we fetch on /persona Jul 4, 2025
@Weves Weves marked this pull request as ready for review July 4, 2025 23:27
@Weves Weves requested a review from a team as a code owner July 4, 2025 23:27
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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) in backend/onyx/db/persona.py
  • Replaced full Persona type with MinimalPersonaSnapshot across frontend components, significantly reducing data transfer payload
  • Switched from selectinload to joinedload in persona queries for better SQL query performance in backend/onyx/db/persona.py
  • Consolidated assistant data fetching into new useAdminPersonas hook with SWR caching in web/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

Comment on lines 151 to +152

let filteredAssistants = filterAssistants(
assistants,
hasAnyConnectors,
hasImageCompatibleModel
);
let filteredAssistants = filterAssistants(assistants);
Copy link
Contributor

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

Comment on lines 66 to +70
.map((id) => assistants.find((assistant) => assistant.id === id))
.filter((assistant): assistant is Persona => assistant !== undefined);
.filter(
(assistant): assistant is MinimalPersonaSnapshot =>
assistant !== undefined
);
Copy link
Contributor

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

Comment on lines +74 to 76
const reorderedPersonas = orderedPersonaIds.map(
(id) => personas.find((persona) => persona.id.toString() === id)!
);
Copy link
Contributor

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

Suggested change
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;
});

Comment on lines +73 to +75
error?.info?.message ||
error?.info?.detail ||
"An unknown error occurred"
Copy link
Contributor

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

Comment on lines +71 to +75
owner=(
MinimalUserSnapshot(id=persona.user.id, email=persona.user.email)
if persona.user
else None
),
Copy link
Contributor

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.

Suggested change
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
),

Comment on lines +14 to +17
const url = buildApiPath("/api/admin/persona", {
include_deleted: includeDeleted.toString(),
get_editable: getEditable.toString(),
});
Copy link
Contributor

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

Copy link
Contributor

@evan-onyx evan-onyx left a 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),
Copy link
Contributor

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),

Copy link
Contributor

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),

Copy link
Contributor

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();
Copy link
Contributor

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) {
Copy link
Contributor

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?

@Weves Weves merged commit adf48de into main Jul 12, 2025
13 of 14 checks passed
@Weves Weves deleted the improve-persona-api-speed branch July 12, 2025 21:15
Weves added a commit that referenced this pull request Jul 14, 2025
Weves added a commit that referenced this pull request Jul 14, 2025
Weves added a commit that referenced this pull request Jul 15, 2025
Weves added a commit that referenced this pull request Jul 15, 2025
* Revert "Revert "Reduce amount of stuff we fetch on `/persona` (#4988)" (#5024)"

This reverts commit f7ed7cd.

* Enhancements / fix re-render

* re-arrange

* greptile
Weves added a commit that referenced this pull request Jul 15, 2025
* Revert "Revert "Reduce amount of stuff we fetch on `/persona` (#4988)" (#5024)"

This reverts commit f7ed7cd.

* Enhancements / fix re-render

* re-arrange

* greptile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants