Skip to content

GO: implement GET /api/v1/datasets/:dataset_id#14834

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
buua436:go001
May 12, 2026
Merged

GO: implement GET /api/v1/datasets/:dataset_id#14834
JinHai-CN merged 3 commits into
infiniflow:mainfrom
buua436:go001

Conversation

@buua436
Copy link
Copy Markdown
Contributor

@buua436 buua436 commented May 12, 2026

What problem does this PR solve?

implement GET /api/v1/datasets/:dataset_id

Type of change

  • Refactoring

@buua436 buua436 requested a review from JinHai-CN May 12, 2026 07:43
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24c2859a-8a20-444c-abd5-680d74c8af38

📥 Commits

Reviewing files that changed from the base of the PR and between 469230b and 3195c69.

📒 Files selected for processing (1)
  • internal/service/datasets.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/datasets.go

📝 Walkthrough

Walkthrough

A new GET /api/v1/datasets/:dataset_id endpoint returns dataset metadata enriched with total document size and associated connectors via new DAO queries and service orchestration.

Changes

Fetch Dataset Details Endpoint

Layer / File(s) Summary
DAO queries for dataset enrichment
internal/dao/connector.go, internal/dao/document.go
Introduces ConnectorDatasetListItem struct and ListByDatasetID query to fetch connectors associated with a dataset, and adds SumSizeByDatasetID to compute total document bytes per dataset.
Service orchestration with DAO composition
internal/service/datasets.go
Adds documentDAO and connectorDAO fields to DatasetsService, initializes them in NewDatasetsService, and implements GetDataset to validate the request, check user permissions, and enrich the dataset response with computed size and connector associations.
HTTP handler and route registration
internal/handler/datasets.go, internal/router/router.go
Implements GetDataset handler for user authentication and parameter extraction, delegating to service; registers the handler at GET /api/v1/datasets/:dataset_id.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Handler
  participant Service
  participant DocumentDAO
  participant ConnectorDAO
  Client->>Handler: GET /datasets/:dataset_id
  Handler->>Service: GetDataset(datasetID, userID)
  Service->>Service: validate and check access
  Service->>DocumentDAO: SumSizeByDatasetID(datasetID)
  DocumentDAO-->>Service: total_size
  Service->>ConnectorDAO: ListByDatasetID(datasetID)
  ConnectorDAO-->>Service: [ConnectorDatasetListItem]
  Service-->>Handler: enriched dataset map
  Handler-->>Client: JSON response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size:S

Poem

🐰 A dataset fetched with care and speed,
Size summed up and connectors seen,
One endpoint hops to gather all,
Clean DAO paths answer the call,
🥕🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description includes the required template sections but lacks meaningful detail—it merely restates the PR title without explaining the problem solved or providing context. Expand the description to explain what problem this endpoint solves (e.g., enabling dataset retrieval functionality) and provide context about the implementation approach.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly summarizes the main change: implementing a new GET endpoint for retrieving a specific dataset by ID.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@buua436 buua436 added ci Continue Integration and removed ci Continue Integration labels May 12, 2026
@buua436 buua436 marked this pull request as ready for review May 12, 2026 08:07
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 12, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/dao/connector.go (1)

69-73: ⚡ Quick win

Add deterministic ordering for connector list results.

Without ORDER BY, connector order can vary across calls. Adding a stable sort (e.g., by connector.id) avoids flaky UI/state diffs.

Suggested diff
 	err := DB.Model(&entity.Connector2Kb{}).
 		Select("connector.id, connector.source, connector.name, connector2kb.auto_parse, connector.status").
 		Joins("JOIN connector ON connector2kb.connector_id = connector.id").
 		Where("connector2kb.kb_id = ?", datasetID).
+		Order("connector.id ASC").
 		Scan(&connectors).Error
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/dao/connector.go` around lines 69 - 73, The query building in the
connector retrieval (the DB.Model(&entity.Connector2Kb{}) ... Joins(...)
Where(...) Scan(&connectors) call) lacks a deterministic ORDER BY, causing
non‑stable connector lists; add an Order clause (e.g., Order("connector.id ASC")
or Order("connector.id")) into that query chain before Scan so results are
consistently sorted by connector.id.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/datasets.go`:
- Around line 532-539: Normalize and validate the incoming datasetID before
calling s.kbDAO.Accessible to avoid false permission failures: after trimming
(strings.TrimSpace(datasetID)) run the same normalization/validation used by
other dataset APIs (e.g., call the project’s dataset ID normalizer/validator
function) and if normalization yields an empty or invalid ID return the existing
error (Lack of "Dataset ID" / CodeDataError); only then call
s.kbDAO.Accessible(normalizedDatasetID, userID) so permission checks use the
canonical ID form.

---

Nitpick comments:
In `@internal/dao/connector.go`:
- Around line 69-73: The query building in the connector retrieval (the
DB.Model(&entity.Connector2Kb{}) ... Joins(...) Where(...) Scan(&connectors)
call) lacks a deterministic ORDER BY, causing non‑stable connector lists; add an
Order clause (e.g., Order("connector.id ASC") or Order("connector.id")) into
that query chain before Scan so results are consistently sorted by connector.id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eca32ef3-2b8f-4e3c-81fa-37c1d34baea7

📥 Commits

Reviewing files that changed from the base of the PR and between f85e18a and 469230b.

📒 Files selected for processing (5)
  • internal/dao/connector.go
  • internal/dao/document.go
  • internal/handler/datasets.go
  • internal/router/router.go
  • internal/service/datasets.go

Comment thread internal/service/datasets.go
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (558ea51) to head (3195c69).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14834   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 12, 2026
@JinHai-CN JinHai-CN merged commit 9ee4818 into infiniflow:main May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants