Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(backend): enhance database indexes for AgentGraph and AgentGraphExecution performance (#10985)

Zamil Majdy7a331651ba97
diff --git a/autogpt_platform/backend/migrations/20250924230049_enhance_graph_and_execution_index/migration.sql b/autogpt_platform/backend/migrations/20250924230049_enhance_graph_and_execution_index/migration.sql
new file mode 100644
index 0000000000..27b32b6fea
--- /dev/null
+++ b/autogpt_platform/backend/migrations/20250924230049_enhance_graph_and_execution_index/migration.sql
@@ -0,0 +1,11 @@
+-- DropIndex
+DROP INDEX "AgentGraph_userId_isActive_idx";
+
+-- DropIndex
+DROP INDEX "AgentGraphExecution_userId_idx";
+
+-- CreateIndex
+CREATE INDEX "AgentGraph_userId_isActive_id_version_idx" ON "AgentGraph"("userId", "isActive", "id", "version");
+
+-- CreateIndex
+CREATE INDEX "AgentGraphExecution_userId_isDeleted_createdAt_idx" ON "AgentGraphExecution"("userId", "isDeleted", "createdAt");
diff --git a/autogpt_platform/backend/schema.prisma b/autogpt_platform/backend/schema.prisma
index 7da9293cf7..7dc1bb90ce 100644
--- a/autogpt_platform/backend/schema.prisma
+++ b/autogpt_platform/backend/schema.prisma
@@ -135,7 +135,7 @@ model AgentGraph {
StoreListingVersions StoreListingVersion[]
@@id(name: "graphVersionId", [id, version])
- @@index([userId, isActive])
+ @@index([userId, isActive, id, version])
@@index([forkedFromId, forkedFromVersion])
}
@@ -377,7 +377,7 @@ model AgentGraphExecution {
sharedAt DateTime?
@@index([agentGraphId, agentGraphVersion])
- @@index([userId])
+ @@index([userId, isDeleted, createdAt])
@@index([createdAt])
@@index([agentPresetId])
@@index([shareToken])