mirror of
https://github.com/langgenius/dify.git
synced 2026-02-09 15:10:13 -05:00
perf(api): Optimize the response time of AppListApi endpoint (#31999)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Literal, TypeAlias
|
from typing import Any, Literal, TypeAlias
|
||||||
@@ -54,6 +55,8 @@ ALLOW_CREATE_APP_MODES = ["chat", "agent-chat", "advanced-chat", "workflow", "co
|
|||||||
|
|
||||||
register_enum_models(console_ns, IconType)
|
register_enum_models(console_ns, IconType)
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AppListQuery(BaseModel):
|
class AppListQuery(BaseModel):
|
||||||
page: int = Field(default=1, ge=1, le=99999, description="Page number (1-99999)")
|
page: int = Field(default=1, ge=1, le=99999, description="Page number (1-99999)")
|
||||||
@@ -499,6 +502,7 @@ class AppListApi(Resource):
|
|||||||
select(Workflow).where(
|
select(Workflow).where(
|
||||||
Workflow.version == Workflow.VERSION_DRAFT,
|
Workflow.version == Workflow.VERSION_DRAFT,
|
||||||
Workflow.app_id.in_(workflow_capable_app_ids),
|
Workflow.app_id.in_(workflow_capable_app_ids),
|
||||||
|
Workflow.tenant_id == current_tenant_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.scalars()
|
.scalars()
|
||||||
@@ -510,12 +514,14 @@ class AppListApi(Resource):
|
|||||||
NodeType.TRIGGER_PLUGIN,
|
NodeType.TRIGGER_PLUGIN,
|
||||||
}
|
}
|
||||||
for workflow in draft_workflows:
|
for workflow in draft_workflows:
|
||||||
|
node_id = None
|
||||||
try:
|
try:
|
||||||
for _, node_data in workflow.walk_nodes():
|
for node_id, node_data in workflow.walk_nodes():
|
||||||
if node_data.get("type") in trigger_node_types:
|
if node_data.get("type") in trigger_node_types:
|
||||||
draft_trigger_app_ids.add(str(workflow.app_id))
|
draft_trigger_app_ids.add(str(workflow.app_id))
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
|
_logger.exception("error while walking nodes, workflow_id=%s, node_id=%s", workflow.id, node_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for app in app_pagination.items:
|
for app in app_pagination.items:
|
||||||
|
|||||||
Reference in New Issue
Block a user