Skip to content

feat[Go]: implement /api/v1/connectors/<connector_id> PATCH - #15512

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
Dimon0000000:main
Jun 2, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
Dimon0000000:main

Conversation

@Dimon0000000

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

As title, all test are passed

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 2, 2026
@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds connector update functionality with optional task rescheduling across the DAO, service, and handler layers. The DAO provides task scheduling helpers; the service implements update logic with partial field support and conditional task rescheduling; the handler exposes an HTTP endpoint to trigger updates.

Changes

Connector Update with Task Rescheduling

Layer / File(s) Summary
DAO Task Scheduling Helpers
internal/dao/connector.go
ScheduleConnectorTasks loads a connector and its mappings, then schedules per-mapping sync and optional prune tasks within a transaction. Helper scheduleConnectorTask prevents duplicate scheduled logs and derives poll state from completed logs. Helper connectorConfigBool interprets boolean config values.
Service Connector Update Logic
internal/service/connector.go
UpdateConnectorRequest DTO holds optional polling frequencies, config, and task control flags. UpdateConnector method validates input, applies partial field updates via DAO, and optionally invokes task cancel/schedule. Status parsing helpers support case-insensitive cancel/schedule interpretation.
Handler Endpoint Integration
internal/handler/connector.go, internal/handler/connector_test.go
Extends service interface with UpdateConnector signature. Handler method decodes JSON request (nested data support), calls service, and returns updated connector. Test helper returns error or preset connector.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#15300: Both PRs modify DAO connector-task scheduling around SyncLogs and sync_deleted_files configuration; the new scheduling helpers in this PR integrate with rebuild/cancel/list-log workflows in PR #15300.
  • infiniflow/ragflow#15259: Both PRs modify handler and service interface layer for connectors; this PR extends with UpdateConnector while the retrieved PR refactors handler/service setup and adds GetConnector.

Suggested reviewers

  • Haruko386

Poem

🐰 A connector update hops into view,
With partial fields and rescheduling true—
DAO layers sync, service applies the care,
Handler threads through with JSON to spare! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is vague and lacks meaningful detail. It only states 'all test are passed' without explaining the problem, implementation approach, or impact, making it insufficient for understanding the PR's purpose. Expand the description with specific details about what problem the PATCH endpoint solves, which connector properties can be updated, and the expected behavior after applying updates.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat[Go]: implement /api/v1/connectors/<connector_id> PATCH' clearly summarizes the main change: implementing a new PATCH endpoint for connectors, which aligns with the changeset.
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.

@Haruko386 Haruko386 added the ci Continue Integration label Jun 2, 2026
@Haruko386
Haruko386 marked this pull request as draft June 2, 2026 08:19
@Haruko386
Haruko386 marked this pull request as ready for review June 2, 2026 08:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
internal/dao/connector.go (1)

304-318: ⚡ Quick win

Reuse connectorConfigBool in RebuildConnector for consistent config parsing.

ScheduleConnectorTasks interprets sync_deleted_files via this helper (handles bool and "1"/"true"/"TRUE"), while RebuildConnector at Line 225 still uses a bare connector.Config["sync_deleted_files"].(bool). A config persisted as a string would schedule a prune task in one path but not the other. Consider routing both through connectorConfigBool.

♻️ Proposed change at Line 225
-		if syncDeletedFiles, _ := connector.Config["sync_deleted_files"].(bool); syncDeletedFiles {
+		if connectorConfigBool(connector.Config, "sync_deleted_files") {
🤖 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 304 - 318, Rework RebuildConnector to
use the existing connectorConfigBool helper for parsing sync_deleted_files
instead of the direct type assertion
connector.Config["sync_deleted_files"].(bool); locate the branch in
RebuildConnector where it currently reads that config (the bare type assertion)
and replace it with a call like connectorConfigBool(connector.Config,
"sync_deleted_files") so parsing of bools and string representations
("1"/"true"/"TRUE") is consistent with ScheduleConnectorTasks.
internal/handler/connector_test.go (1)

48-53: ⚡ Quick win

Add a handler test for the new UpdateConnector endpoint.

The fake gains an UpdateConnector method to satisfy the interface, but no test (e.g. TestConnectorHandlerUpdateConnector) exercises the new handler/decoder path including the nested data object handling and success/error code mapping. Adding coverage parallel to the existing Delete/ListLogs tests would protect the new endpoint.

Want me to draft a TestConnectorHandlerUpdateConnector covering success, not-found, and unauthorized cases plus the nested data payload?

🤖 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/handler/connector_test.go` around lines 48 - 53, Add a new
table-driven test named TestConnectorHandlerUpdateConnector that exercises the
handler and decoder path for the new UpdateConnector endpoint: call the HTTP
handler that routes to ConnectorHandler.UpdateConnector (or equivalent) and use
the request decoder (e.g., decodeUpdateConnectorRequest) to verify nested "data"
JSON is parsed into service.UpdateConnectorRequest correctly; mock responses via
the fakeConnectorService.UpdateConnector to cover success (returning
*entity.Connector and common.CodeSuccess), not-found (returning nil and
common.CodeNotFound), and unauthorized (returning nil and
common.CodeUnauthorized) cases, and assert HTTP status codes and response bodies
mirror the existing Delete/ListLogs tests' assertions for success/error mapping.
Ensure the test constructs the nested data payload, wires the
fakeConnectorService into the handler, and checks both decoded request contents
and mapped HTTP responses.
🤖 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/dao/connector.go`:
- Around line 272-282: The query that finds the latest completed SyncLogs uses
Order("update_time DESC") which may reference a non-existent column (compare
with ListLogsByConnectorID which orders by update_date); update this to use the
actual timestamp column name defined on entity.SyncLogs (e.g., "update_date" or
the BaseModel field name) so the First(&latest) call doesn't fail silently, and
ensure pollRangeStart is assigned from latest.PollRangeEnd and totalDocsIndexed
from latest.TotalDocsIndexed only after the corrected query (symbols: SyncLogs,
ListLogsByConnectorID, update_time/update_date, pollRangeStart, PollRangeEnd,
totalDocsIndexed).

---

Nitpick comments:
In `@internal/dao/connector.go`:
- Around line 304-318: Rework RebuildConnector to use the existing
connectorConfigBool helper for parsing sync_deleted_files instead of the direct
type assertion connector.Config["sync_deleted_files"].(bool); locate the branch
in RebuildConnector where it currently reads that config (the bare type
assertion) and replace it with a call like connectorConfigBool(connector.Config,
"sync_deleted_files") so parsing of bools and string representations
("1"/"true"/"TRUE") is consistent with ScheduleConnectorTasks.

In `@internal/handler/connector_test.go`:
- Around line 48-53: Add a new table-driven test named
TestConnectorHandlerUpdateConnector that exercises the handler and decoder path
for the new UpdateConnector endpoint: call the HTTP handler that routes to
ConnectorHandler.UpdateConnector (or equivalent) and use the request decoder
(e.g., decodeUpdateConnectorRequest) to verify nested "data" JSON is parsed into
service.UpdateConnectorRequest correctly; mock responses via the
fakeConnectorService.UpdateConnector to cover success (returning
*entity.Connector and common.CodeSuccess), not-found (returning nil and
common.CodeNotFound), and unauthorized (returning nil and
common.CodeUnauthorized) cases, and assert HTTP status codes and response bodies
mirror the existing Delete/ListLogs tests' assertions for success/error mapping.
Ensure the test constructs the nested data payload, wires the
fakeConnectorService into the handler, and checks both decoded request contents
and mapped HTTP responses.
🪄 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: 6bd1218f-624b-40b3-8f7e-b57d2c20ed35

📥 Commits

Reviewing files that changed from the base of the PR and between a98889c and 67b24d0.

📒 Files selected for processing (4)
  • internal/dao/connector.go
  • internal/handler/connector.go
  • internal/handler/connector_test.go
  • internal/service/connector.go

Comment thread internal/dao/connector.go
Comment on lines +272 to +282
var latest entity.SyncLogs
err := tx.Where("connector_id = ? AND kb_id = ? AND task_type = ? AND status = ?", connectorID, kbID, taskType, string(entity.TaskStatusDone)).
Order("update_time DESC").
First(&latest).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
if err == nil {
pollRangeStart = latest.PollRangeEnd
totalDocsIndexed = latest.TotalDocsIndexed
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Verify the update_time column used for ordering the latest completed log.

This query orders by update_time DESC, but the existing ListLogsByConnectorID query (Line 353) orders SyncLogs by update_date. If update_time is not a real column on the sync_logs table, this First(...) call will error (and only gorm.ErrRecordNotFound is tolerated). Please confirm the column exists; otherwise the "resume from last completed poll" logic silently breaks the schedule.

#!/bin/bash
# Find BaseModel/SyncLogs column definitions to confirm update_time exists
ast-grep --pattern 'type BaseModel struct {
  $$$
}'
echo "----- update_time / update_date references on sync logs -----"
rg -nP "update_(time|date)" --type=go -C2
🤖 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 272 - 282, The query that finds the
latest completed SyncLogs uses Order("update_time DESC") which may reference a
non-existent column (compare with ListLogsByConnectorID which orders by
update_date); update this to use the actual timestamp column name defined on
entity.SyncLogs (e.g., "update_date" or the BaseModel field name) so the
First(&latest) call doesn't fail silently, and ensure pollRangeStart is assigned
from latest.PollRangeEnd and totalDocsIndexed from latest.TotalDocsIndexed only
after the corrected query (symbols: SyncLogs, ListLogsByConnectorID,
update_time/update_date, pollRangeStart, PollRangeEnd, totalDocsIndexed).

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (a98889c) to head (67b24d0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15512   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ 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.

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 2, 2026
@JinHai-CN
JinHai-CN merged commit 5f89264 into infiniflow:main Jun 2, 2026
1 check passed
JinHai-CN pushed a commit that referenced this pull request Jun 25, 2026
### What problem does this PR solve?

As title

/api/v1/connectors/<connector_id> PATCH was implemented in #15512

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants