Skip to content

🚀 fix(model-sync): avoid unnecessary upstream fetch while keeping ove… - #2528

Merged
seefs001 merged 1 commit into
mainfrom
fix/model-sync-overwrite-empty-missing
Dec 26, 2025
Merged

seefs001 merged 1 commit into
mainfrom
fix/model-sync-overwrite-empty-missing

Conversation

@t0ng7u

@t0ng7u t0ng7u commented Dec 25, 2025 •

Copy link
Copy Markdown
Collaborator

…rwrite updates working

  • Only short-circuit when there are no missing models AND no overwrite fields requested
  • Preserve overwrite behavior even when the missing-model list is empty
  • Always return empty arrays (not null) for list fields to keep API responses stable
  • Clarify SyncUpstreamModels behavior in comments (create missing models + optional overwrite updates)

Summary by CodeRabbit

  • Refactor
    • Model synchronization now skips unnecessary upstream requests when no models need to be created or updated.

✏️ Tip: You can customize this high-level summary in your review settings.

…rwrite updates working

- Only short-circuit when there are no missing models AND no overwrite fields requested
- Preserve overwrite behavior even when the missing-model list is empty
- Always return empty arrays (not null) for list fields to keep API responses stable
- Clarify SyncUpstreamModels behavior in comments (create missing models + optional overwrite updates)
@coderabbitai

coderabbitai Bot commented Dec 25, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes modify SyncUpstreamModels in controller/model_sync.go to add an early-exit optimization that skips upstream fetches when no model creation or overwriting is needed. Additional updates include proper context cancellation via defer, explicit empty slice initialization using make(), and enhanced documentation of the function's behavior.

Changes

Cohort / File(s) Summary
Early-exit optimization & context management
controller/model_sync.go
Added early-exit logic to return a no-op response when no missing models and no overwrite flag; introduced defer cancel() for context cleanup; initialized slices explicitly with make([]string, 0) instead of nil; enhanced commentary documenting default behavior (create-only) and overwrite support.
Whitespace
service/convert.go
Added empty line; no functional changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A hop through the code, a skip through the net,
When there's nothing to sync, why fetch yet?
With contexts so clean and slices so tidy,
This function runs faster—oh, how delightfully spry!
Context.cancel() bows with a flourish so fine, ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is directly related to the main change: avoiding unnecessary upstream fetches in model-sync while preserving overwrite functionality, which matches the PR's core objective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/model-sync-overwrite-empty-missing

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3c854f and 83fbaba.

📒 Files selected for processing (2)
  • controller/model_sync.go
  • service/convert.go
🔇 Additional comments (5)
service/convert.go (1)

404-404: No functional change.

This is a whitespace-only modification with no impact on logic or behavior.

controller/model_sync.go (4)

252-255: Good documentation addition.

The comments clearly explain the function's dual behavior: creating missing models by default and optionally overwriting existing models when sync_official is enabled.


266-286: Solid optimization for avoiding unnecessary upstream fetches.

The early-exit correctly short-circuits when there's nothing to sync (no missing models, no overwrite fields). The response structure is consistent with the normal path, and empty arrays ensure stable API responses.


290-291: Proper context cleanup with defer.

Adding defer cancel() ensures the timeout context is properly released on all exit paths, preventing resource leaks. This is the correct pattern for context management in Go.


334-336: Ensures consistent JSON serialization for empty arrays.

Using make([]string, 0) instead of nil declarations guarantees these slices serialize as [] rather than null in JSON responses, providing stable API output for clients.


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.

@t0ng7u
t0ng7u requested a review from Calcium-Ion December 25, 2025 15:25
@t0ng7u t0ng7u self-assigned this Dec 25, 2025
@t0ng7u t0ng7u added the enhancement New feature or request label Dec 25, 2025
@seefs001
seefs001 merged commit 31a3487 into main Dec 26, 2025
@Calcium-Ion
Calcium-Ion deleted the fix/model-sync-overwrite-empty-missing branch January 29, 2026 17:10
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants