Skip to content

Fetch package versions concurrently - #29

Open
inayayousfi wants to merge 2 commits into
mainfrom
14-make-fetching-packages-version-concurrent
Open

Fetch package versions concurrently#29
inayayousfi wants to merge 2 commits into
mainfrom
14-make-fetching-packages-version-concurrent

Conversation

@inayayousfi

@inayayousfi inayayousfi commented May 9, 2026

Copy link
Copy Markdown
Owner

Closes #14

Summary by CodeRabbit

  • Chores
    • Updated indirect dependencies
    • Enhanced dependency update processing

Review Change Stack

14-make-fetching-packages-version-concurrent
@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ZiedYousfi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 40 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 163d23be-0e8d-4712-9e16-779d3a8dd360

📥 Commits

Reviewing files that changed from the base of the PR and between bcce738 and 0fbe428.

📒 Files selected for processing (1)
  • npm.go
📝 Walkthrough

Walkthrough

This PR adds concurrency to npm package version checking. The code introduces a new dependency on golang.org/x/sync and refactors updateDependencies to process multiple packages in parallel using an error group with a concurrency limit of 8, protecting shared writes with a mutex.

Changes

Concurrent NPM Dependency Updates

Layer / File(s) Summary
Dependency Declaration
go.mod
golang.org/x/sync v0.20.0 is added as an indirect dependency.
Concurrent Imports
npm.go
Import block adds context, sync, and golang.org/x/sync/errgroup to support concurrent goroutine management.
Concurrent Update Logic
npm.go
updateDependencies refactored to spawn goroutines (capped at 8) per dependency, each fetching npm registry data and updating shared state via mutex-protected writes; errors propagate through g.Wait().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops through the registry, eight at a time,
No more waiting sequential, now parallel and prime!
A mutex guards the bunny's shared cache,
As errgroup coordinates the npm package dash! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fetch package versions concurrently' accurately and concisely summarizes the main change - implementing concurrent fetching in the updateDependencies function.
Linked Issues check ✅ Passed The PR implements concurrent package version fetching using errgroup with an 8-goroutine limit, directly addressing the requirement to make fetching concurrent from issue #14.
Out of Scope Changes check ✅ Passed All changes are in-scope: the go.mod update adds the required golang.org/x/sync dependency, and npm.go modifications implement the concurrent fetching requirement with proper synchronization.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 14-make-fetching-packages-version-concurrent

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.

@inayayousfi

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (3)
npm.go (2)

169-173: 💤 Low value

Minor cleanups: misleading comment and unnecessary loop variable shadow.

  • Line 169: "Rate limits hihi" — SetLimit(8) is a concurrency limit, not a rate limit. They're different things (concurrent in-flight vs. requests-per-time). Worth clarifying or removing.
  • Line 173: i := i is no longer required. go.mod declares go 1.25.0, and per-iteration loop variables have been the default since Go 1.22, so the shadow is dead code.
Suggested cleanup
-	// Rate limits hihi
-	g.SetLimit(8)
+	// Cap concurrent npm registry requests to avoid overwhelming the host.
+	g.SetLimit(8)

 	for i := range deps {
-		i := i
-
 		g.Go(func() 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 `@npm.go` around lines 169 - 173, The comment "Rate limits hihi" is misleading
for G.SetLimit(8) because SetLimit controls concurrency (in-flight goroutines)
not request rate; update or remove the comment to accurately say it sets a
concurrency limit (e.g., "Limit concurrency to 8"). Also remove the unnecessary
per-iteration shadow `i := i` inside the loop `for i := range deps { ... }`
since Go 1.22+ fixes loop variable capture; keep using `i` directly in the
goroutine or closure.

167-167: ⚡ Quick win

Drop WithContext since the context is unused and provides no cancellation benefit.

errgroup.WithContext returns a context that cancels on the first error, but you discard it with _. Neither getNPMPackageLatestVersion nor getOtherNPMPackageVersions accept a context parameter, and both use client.Get() without context propagation. This means when one fetch fails, the remaining in-flight HTTP requests continue to completion before g.Wait() returns.

Replace with a plain errgroup.Group and remove the "context" import:

Suggested change
-	g, _ := errgroup.WithContext(context.Background())
-
-	// Rate limits hihi
-	g.SetLimit(8)
+	var g errgroup.Group
+	g.SetLimit(8) // bound concurrent registry requests

Remove the "context" import from the imports section.

If proper cancellation on error is desired in the future, thread the context into the HTTP calls via http.NewRequestWithContext instead.

🤖 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 `@npm.go` at line 167, The code currently calls errgroup.WithContext and
discards the returned context (g, _ := errgroup.WithContext(...)) while the
helper functions getNPMPackageLatestVersion and getOtherNPMPackageVersions do
not accept contexts or propagate them into client.Get(), so replace the
WithContext usage with a plain errgroup.Group (use var g errgroup.Group or
errgroup.Group{} as appropriate) and remove the unused "context" import; if you
later want cancellation on first error, thread a context through
getNPMPackageLatestVersion/getOtherNPMPackageVersions and use
http.NewRequestWithContext when calling client.Get() so g.Wait() can cancel
in-flight requests.
go.mod (1)

21-21: ⚡ Quick win

golang.org/x/sync should be a direct dependency, not indirect.

npm.go now imports golang.org/x/sync/errgroup directly, so this dependency is used by your own code rather than transitively pulled in. Running go mod tidy will likely move it out of the indirect group; consider running it now to keep go.mod accurate.

Proposed change
 require (
 	github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
 	...
 	golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
-	golang.org/x/sync v0.20.0 // indirect
 	golang.org/x/sys v0.30.0 // indirect
 )
+
+require golang.org/x/sync v0.20.0

Or simply run go mod tidy and let the toolchain place it correctly.

🤖 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 `@go.mod` at line 21, go.mod lists golang.org/x/sync as indirect but npm.go now
imports golang.org/x/sync/errgroup directly; update module dependencies by
running "go mod tidy" (or add golang.org/x/sync at the correct version as a
direct require) so the dependency is recorded as direct in go.mod; check npm.go
(the import of golang.org/x/sync/errgroup) to confirm and then commit the
updated go.mod/go.sum.
🤖 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 `@npm.go`:
- Around line 162-245: The concurrent loop appends to updates in completion
order, breaking determinism; instead preallocate a results slice of length
len(deps) (e.g. results := make([]DependencyUpdate, len(deps))) and in the
goroutine write the computed update into results[i] (using the same i capture)
rather than appending; after g.Wait, build the final updates slice by iterating
results in index order and filtering out empty/zero entries. Keep the existing
deps[i] assignment and its mutex around it (or use a separate mutex only if you
choose to make writes to results concurrent), and leave calls like
getNPMPackageLatestVersion, classifyDependencyUpdate,
getLatestPatchNPMPackageVersion and mergeDependencyVersion unchanged.

---

Nitpick comments:
In `@go.mod`:
- Line 21: go.mod lists golang.org/x/sync as indirect but npm.go now imports
golang.org/x/sync/errgroup directly; update module dependencies by running "go
mod tidy" (or add golang.org/x/sync at the correct version as a direct require)
so the dependency is recorded as direct in go.mod; check npm.go (the import of
golang.org/x/sync/errgroup) to confirm and then commit the updated
go.mod/go.sum.

In `@npm.go`:
- Around line 169-173: The comment "Rate limits hihi" is misleading for
G.SetLimit(8) because SetLimit controls concurrency (in-flight goroutines) not
request rate; update or remove the comment to accurately say it sets a
concurrency limit (e.g., "Limit concurrency to 8"). Also remove the unnecessary
per-iteration shadow `i := i` inside the loop `for i := range deps { ... }`
since Go 1.22+ fixes loop variable capture; keep using `i` directly in the
goroutine or closure.
- Line 167: The code currently calls errgroup.WithContext and discards the
returned context (g, _ := errgroup.WithContext(...)) while the helper functions
getNPMPackageLatestVersion and getOtherNPMPackageVersions do not accept contexts
or propagate them into client.Get(), so replace the WithContext usage with a
plain errgroup.Group (use var g errgroup.Group or errgroup.Group{} as
appropriate) and remove the unused "context" import; if you later want
cancellation on first error, thread a context through
getNPMPackageLatestVersion/getOtherNPMPackageVersions and use
http.NewRequestWithContext when calling client.Get() so g.Wait() can cancel
in-flight requests.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c98fc20-1129-4df7-a44a-1c087900e2ed

📥 Commits

Reviewing files that changed from the base of the PR and between 2707c40 and bcce738.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • go.mod
  • npm.go

Comment thread npm.go
Cap npm registry requests with errgroup while avoiding the extra context wrapper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make fetching packages version concurrent

1 participant