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(market): swap to prisma direct query (#8246)
Nicholas Tindle9748cd08bf2e
diff --git a/autogpt_platform/market/market/db.py b/autogpt_platform/market/market/db.pyindex cbc8d59c04..5f0d983891 100644--- a/autogpt_platform/market/market/db.py+++ b/autogpt_platform/market/market/db.py@@ -593,24 +593,24 @@ async def get_not_featured_agents(agents = await prisma.client.get_client().query_raw(query=f"""SELECT- "Agents".id,- "Agents"."createdAt",- "Agents"."updatedAt",- "Agents".version,- "Agents".name,- LEFT("Agents".description, 500) AS description,- "Agents".author,- "Agents".keywords,- "Agents".categories,- "Agents".graph,- "Agents"."submissionStatus",- "Agents"."submissionDate",- "Agents".search::text AS search- FROM "Agents"- LEFT JOIN "FeaturedAgent" ON "Agents"."id" = "FeaturedAgent"."agentId"- WHERE ("FeaturedAgent"."agentId" IS NULL OR "FeaturedAgent"."featuredCategories" = '{{}}')- AND "Agents"."submissionStatus" = 'APPROVED'- ORDER BY "Agents"."createdAt" DESC+ "market"."Agents".id,+ "market"."Agents"."createdAt",+ "market"."Agents"."updatedAt",+ "market"."Agents".version,+ "market"."Agents".name,+ LEFT("market"."Agents".description, 500) AS description,+ "market"."Agents".author,+ "market"."Agents".keywords,+ "market"."Agents".categories,+ "market"."Agents".graph,+ "market"."Agents"."submissionStatus",+ "market"."Agents"."submissionDate",+ "market"."Agents".search::text AS search+ FROM "market"."Agents"+ LEFT JOIN "market"."FeaturedAgent" ON "market"."Agents"."id" = "market"."FeaturedAgent"."agentId"+ WHERE ("market"."FeaturedAgent"."agentId" IS NULL OR "market"."FeaturedAgent"."featuredCategories" = '{{}}')+ AND "market"."Agents"."submissionStatus" = 'APPROVED'+ ORDER BY "market"."Agents"."createdAt" DESCLIMIT {page_size} OFFSET {page_size * (page - 1)}""",model=prisma.models.Agents,@@ -630,24 +630,20 @@ async def get_all_categories() -> market.model.CategoriesResponse:CategoriesResponse: A list of unique categories."""try:- categories = await prisma.client.get_client().query_first(- query="""-SELECT ARRAY_AGG(DISTINCT category ORDER BY category) AS unique_categories-FROM (- SELECT UNNEST(categories) AS category- FROM "Agents"-) subquery;-""",- model=market.model.CategoriesResponse,- )- if not categories:- return market.model.CategoriesResponse(unique_categories=[])+ agents = await prisma.models.Agents.prisma().find_many(distinct=["categories"])++ # Aggregate categories on the Python side+ all_categories = set()+ for agent in agents:+ all_categories.update(agent.categories)++ unique_categories = sorted(list(all_categories))- return categories+ return market.model.CategoriesResponse(unique_categories=unique_categories)except prisma.errors.PrismaError as e:raise AgentQueryError(f"Database query failed: {str(e)}")except Exception as e:- # raise AgentQueryError(f"Unexpected error occurred: {str(e)}")+ # Return an empty list of categories in case of unexpected errorsreturn market.model.CategoriesResponse(unique_categories=[])