Repository navigation
fix: fix some bugs in check_conn and drop_inst - #16180
Conversation
📝 WalkthroughWalkthrough
ChangesDropProviderInstances error handling and API key field fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
internal/service/model_service.go (2)
903-913: ⚡ Quick winConsider bulk query to avoid N+1 database calls.
The loop queries the database once per instance name. For larger instance lists, this could become a performance bottleneck. A single query with
WHERE instance_name IN (...)followed by local set-differencing would reduce round trips.Not urgent given typical usage patterns, but worth considering if instance lists grow.
🤖 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/service/model_service.go` around lines 903 - 913, The loop around GetByProviderIDAndInstanceName is making individual database queries for each instance name, creating an N+1 query problem. Refactor this to make a single database query that fetches all model instances for the given providerID using an IN clause with all instanceNames at once, then perform local set-differencing in memory to identify missingInstanceNames by comparing the returned instances against the requested instanceNames list.
952-964: ⚖️ Poor tradeoffMultiple deletes without transaction can leave partial state.
The loop performs
DeleteByProviderIDAndInstanceIDthenDeleteByProviderIDAndInstanceNamefor each instance. If a failure occurs mid-loop (e.g., after deleting some instances but not others, or after deleting models but before deleting the instance row), the database is left in an inconsistent state with no rollback.Consider wrapping the entire deletion loop in a database transaction to ensure atomicity.
🤖 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/service/model_service.go` around lines 952 - 964, The deletion operations within the loop iterating over modelInstances (calls to m.modelDAO.DeleteByProviderIDAndInstanceID and m.modelInstanceDAO.DeleteByProviderIDAndInstanceName) are not wrapped in a database transaction, risking partial state if an error occurs mid-loop. Wrap the entire loop in a database transaction that begins before the loop starts and commits only after all deletions complete successfully, ensuring that any error during the loop triggers a rollback to maintain consistency.
🤖 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.
Nitpick comments:
In `@internal/service/model_service.go`:
- Around line 903-913: The loop around GetByProviderIDAndInstanceName is making
individual database queries for each instance name, creating an N+1 query
problem. Refactor this to make a single database query that fetches all model
instances for the given providerID using an IN clause with all instanceNames at
once, then perform local set-differencing in memory to identify
missingInstanceNames by comparing the returned instances against the requested
instanceNames list.
- Around line 952-964: The deletion operations within the loop iterating over
modelInstances (calls to m.modelDAO.DeleteByProviderIDAndInstanceID and
m.modelInstanceDAO.DeleteByProviderIDAndInstanceName) are not wrapped in a
database transaction, risking partial state if an error occurs mid-loop. Wrap
the entire loop in a database transaction that begins before the loop starts and
commits only after all deletions complete successfully, ensuring that any error
during the loop triggers a rollback to maintain consistency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 15fa7f42-5e41-40ee-ae9b-82b66fd991ba
📒 Files selected for processing (2)
internal/handler/providers.gointernal/service/model_service.go
What problem does this PR solve?
As title:
BUG fixed was verified in RAGFlow CLI
CHECK INSTANCE 'instance_name' FROM 'provider_name'
fixed:
DROP INSTANCE 'instance_name' FROM 'provider_name'
fixed:
Type of change