dify/api/agent-notes/services/dataset_service.py.md
盐粒 Yanli 62ac02a568
feat: Download the uploaded files (#31068)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-19 16:48:13 +08:00

1013 B

Purpose

api/services/dataset_service.py hosts dataset/document service logic used by console and API controllers.

Batch document operations

  • Batch document workflows should avoid N+1 database queries by using set-based lookups.
  • Tenant checks must be enforced consistently across dataset/document operations.
  • DocumentService.get_documents_by_ids(...) fetches documents for a dataset using id.in_(...).
  • FileService.get_upload_files_by_ids(...) performs tenant-scoped batch lookup for UploadFile (dedupes ids with set(...)).
  • DocumentService.get_document_download_url(...) and prepare_document_batch_download_zip(...) handle dataset/document permission checks plus Document -> UploadFile validation for download endpoints.

Verification plan

  • Exercise document list and download endpoints that use the service helpers.
  • Confirm batch download uses constant query count for documents + upload files.
  • Request a ZIP with a missing document id and confirm a 404 is returned.