From 57fe0e849eb7f83a4eb1195295abcfc6aca5e456 Mon Sep 17 00:00:00 2001 From: Thomas Draier Date: Wed, 16 Oct 2024 16:07:06 +0200 Subject: [PATCH 1/2] Split query to fetch agent_configurations --- front/lib/api/assistant/configuration.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/front/lib/api/assistant/configuration.ts b/front/lib/api/assistant/configuration.ts index bf42a9892557..9e43ac0c1fd7 100644 --- a/front/lib/api/assistant/configuration.ts +++ b/front/lib/api/assistant/configuration.ts @@ -307,17 +307,27 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions( case "list": const user = auth.user(); - return AgentConfiguration.findAll({ + const sharedAssistants = await AgentConfiguration.findAll({ + ...baseAgentsSequelizeQuery, + where: { + ...baseWhereConditions, + scope: { [Op.in]: ["workspace", "published"] }, + }, + }); + if (!user) { + return sharedAssistants; + } + + const userAssistants = await AgentConfiguration.findAll({ ...baseAgentsSequelizeQuery, where: { ...baseWhereConditions, - [Op.or]: [ - { scope: { [Op.in]: ["workspace", "published"] } }, - { authorId: user?.id }, - ], + authorId: user.id, + scope: { [Op.notIn]: ["workspace", "published"] }, }, }); + return [...sharedAssistants, ...userAssistants]; default: if (typeof agentsGetView === "object" && "agentIds" in agentsGetView) { return AgentConfiguration.findAll({ From b72f41a5c67fe328c3c3cc06b8d291e979de3888 Mon Sep 17 00:00:00 2001 From: Thomas Draier Date: Wed, 16 Oct 2024 18:09:27 +0200 Subject: [PATCH 2/2] optimize query --- front/lib/api/assistant/configuration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/lib/api/assistant/configuration.ts b/front/lib/api/assistant/configuration.ts index 9e43ac0c1fd7..63b34ee0c818 100644 --- a/front/lib/api/assistant/configuration.ts +++ b/front/lib/api/assistant/configuration.ts @@ -323,7 +323,7 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions( where: { ...baseWhereConditions, authorId: user.id, - scope: { [Op.notIn]: ["workspace", "published"] }, + scope: "private", }, });