Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore: use selectinload instead of joinedload in conversation query (#33014)

Eric Cao18e4ec73d6b1
diff --git a/api/controllers/console/app/conversation.py b/api/controllers/console/app/conversation.py
index 5eb61493c38..74750981dd5 100644
--- a/api/controllers/console/app/conversation.py
+++ b/api/controllers/console/app/conversation.py
@@ -5,7 +5,7 @@ from flask import abort, request
from flask_restx import Resource, fields, marshal_with
from pydantic import BaseModel, Field, field_validator
from sqlalchemy import func, or_
-from sqlalchemy.orm import joinedload
+from sqlalchemy.orm import selectinload
from werkzeug.exceptions import NotFound
from controllers.console import console_ns
@@ -376,8 +376,12 @@ class CompletionConversationApi(Resource):
# FIXME, the type ignore in this file
if args.annotation_status == "annotated":
- query = query.options(joinedload(Conversation.message_annotations)).join( # type: ignore
- MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
+ query = (
+ query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type]
+ .join( # type: ignore
+ MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
+ )
+ .distinct()
)
elif args.annotation_status == "not_annotated":
query = (
@@ -511,8 +515,12 @@ class ChatConversationApi(Resource):
match args.annotation_status:
case "annotated":
- query = query.options(joinedload(Conversation.message_annotations)).join( # type: ignore
- MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
+ query = (
+ query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type]
+ .join( # type: ignore
+ MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
+ )
+ .distinct()
)
case "not_annotated":
query = (