-
Notifications
You must be signed in to change notification settings - Fork 1
feat(solver): prefer highest versions + fix caching/dedupe #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| [tools] | ||
| go = "1.25.3" | ||
| go = "latest" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,9 @@ | ||||||||||
| package pubgrub | ||||||||||
|
|
||||||||||
| import "fmt" | ||||||||||
| import ( | ||||||||||
| "fmt" | ||||||||||
| "sync" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| // CachedSource wraps a Source and caches GetVersions and GetDependencies calls | ||||||||||
| // to improve performance when the same queries are made repeatedly. | ||||||||||
|
|
@@ -23,6 +26,8 @@ import "fmt" | |||||||||
| type CachedSource struct { | ||||||||||
| source Source | ||||||||||
|
|
||||||||||
| mu sync.Mutex | ||||||||||
|
|
||||||||||
| // Cache for GetVersions results | ||||||||||
| versionsCache map[Name][]Version | ||||||||||
| versionsCalls int | ||||||||||
|
|
@@ -45,27 +50,37 @@ func NewCachedSource(source Source) *CachedSource { | |||||||||
|
|
||||||||||
| // GetVersions returns all available versions for a package, caching the result. | ||||||||||
| func (c *CachedSource) GetVersions(name Name) ([]Version, error) { | ||||||||||
| c.mu.Lock() | ||||||||||
| c.versionsCalls++ | ||||||||||
|
|
||||||||||
| // Check cache first | ||||||||||
| if versions, ok := c.versionsCache[name]; ok { | ||||||||||
| c.versionsCacheHits++ | ||||||||||
| return versions, nil | ||||||||||
| out := cloneVersions(versions) | ||||||||||
| c.mu.Unlock() | ||||||||||
| return out, nil | ||||||||||
| } | ||||||||||
| c.mu.Unlock() | ||||||||||
|
|
||||||||||
| // Cache miss - fetch from underlying source | ||||||||||
| versions, err := c.source.GetVersions(name) | ||||||||||
| if err != nil { | ||||||||||
| return nil, err | ||||||||||
| } | ||||||||||
|
|
||||||||||
| cloned := cloneVersions(versions) | ||||||||||
|
|
||||||||||
| // Store in cache | ||||||||||
| c.versionsCache[name] = versions | ||||||||||
| return versions, nil | ||||||||||
| c.mu.Lock() | ||||||||||
| c.versionsCache[name] = cloned | ||||||||||
| c.mu.Unlock() | ||||||||||
|
|
||||||||||
| return cloneVersions(cloned), nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // GetDependencies returns dependencies for a specific package version, caching the result. | ||||||||||
| func (c *CachedSource) GetDependencies(name Name, version Version) ([]Term, error) { | ||||||||||
| c.mu.Lock() | ||||||||||
| c.depsCalls++ | ||||||||||
|
|
||||||||||
| // Create cache key from name and version | ||||||||||
|
|
@@ -74,18 +89,26 @@ func (c *CachedSource) GetDependencies(name Name, version Version) ([]Term, erro | |||||||||
| // Check cache first | ||||||||||
| if deps, ok := c.depsCache[key]; ok { | ||||||||||
| c.depsCacheHits++ | ||||||||||
| return deps, nil | ||||||||||
| out := cloneTerms(deps) | ||||||||||
| c.mu.Unlock() | ||||||||||
|
Comment on lines
+92
to
+93
|
||||||||||
| out := cloneTerms(deps) | |
| c.mu.Unlock() | |
| c.mu.Unlock() | |
| out := cloneTerms(deps) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutex is unlocked after cloning but before returning. If cloning is expensive, consider cloning after unlocking to reduce lock contention. Move
c.mu.Unlock()to line 58 (before cloning).