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.

fix: page/limit param not effective (#18196)

诗浓4166f73d9da4
diff --git a/api/controllers/service_api/dataset/segment.py b/api/controllers/service_api/dataset/segment.py
index 3d5869c3716..2a79e15cc5d 100644
--- a/api/controllers/service_api/dataset/segment.py
+++ b/api/controllers/service_api/dataset/segment.py
@@ -122,6 +122,8 @@ class SegmentApi(DatasetApiResource):
tenant_id=current_user.current_tenant_id,
status_list=args["status"],
keyword=args["keyword"],
+ page=page,
+ limit=limit,
)
response = {
diff --git a/api/services/dataset_service.py b/api/services/dataset_service.py
index deb6be5a43e..b08d70489a4 100644
--- a/api/services/dataset_service.py
+++ b/api/services/dataset_service.py
@@ -2175,7 +2175,13 @@ class SegmentService:
@classmethod
def get_segments(
- cls, document_id: str, tenant_id: str, status_list: list[str] | None = None, keyword: str | None = None
+ cls,
+ document_id: str,
+ tenant_id: str,
+ status_list: list[str] | None = None,
+ keyword: str | None = None,
+ page: int = 1,
+ limit: int = 20,
):
"""Get segments for a document with optional filtering."""
query = DocumentSegment.query.filter(
@@ -2188,10 +2194,11 @@ class SegmentService:
if keyword:
query = query.filter(DocumentSegment.content.ilike(f"%{keyword}%"))
- segments = query.order_by(DocumentSegment.position.asc()).all()
- total = len(segments)
+ paginated_segments = query.order_by(DocumentSegment.position.asc()).paginate(
+ page=page, per_page=limit, max_per_page=100, error_out=False
+ )
- return segments, total
+ return paginated_segments.items, paginated_segments.total
@classmethod
def update_segment_by_id(