fix: resolve the progress bar stuck when build 10k files#161
Conversation
|
""" WalkthroughThe changes in this pull request modify the internal progress bar implementation by explicitly setting the refresh rate to 300 milliseconds and refactoring the way progress bar messages are handled. The message formatting and storage are now consolidated into a dedicated struct, eliminating redundant locking and map lookups during decorator rendering. The progress bar creation and management logic is streamlined, with the new struct instance stored in the internal map and used for proxy reader creation. There are no changes to exported function or method signatures. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ProgressBar
participant mpb.Progress
participant progressBar (struct)
participant Bar
Caller->>ProgressBar: Add(size, prompt, name, reader)
ProgressBar->>progressBar (struct): Create instance with size and formatted msg
ProgressBar->>mpb.Progress: New(size, decorators)
mpb.Progress-->>progressBar (struct): Return Bar instance
progressBar (struct)->>Bar: Store Bar
progressBar (struct)->>ProgressBar: Store in bars map
progressBar (struct)->>Bar: ProxyReader(reader)
Bar-->>Caller: Return proxy reader
Assessment against linked issues
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Signed-off-by: chlins <chlins.zhang@gmail.com>
0c9229b to
dae87f3
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/pb/pb.go (1)
89-89: Remove embedded field "Bar" from selectorThe linter identified that the embedded field "Bar" could be removed from the selector.
- return newBar.Bar.ProxyReader(reader) + return newBar.ProxyReader(reader)Since
Baris an embedded field in theprogressBarstruct, you can access its methods directly without specifying the field name.🧰 Tools
🪛 GitHub Actions: Lint
[error] 89-89: staticcheck: could remove embedded field "Bar" from selector (QF1008)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/pb/pb.go(4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Lint
internal/pb/pb.go
[error] 89-89: staticcheck: could remove embedded field "Bar" from selector (QF1008)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (5)
internal/pb/pb.go (5)
23-23: Good addition of time packageAdding the time package import is necessary to support the new refresh rate setting for the progress bar.
51-51: Great fix for the progress bar stuck issueSetting a refresh rate of 300ms is an excellent solution to prevent the progress bar from getting stuck when building 10k files. This explicit refresh rate ensures the UI updates at regular intervals regardless of processing speed.
66-67: Good refactoring of progress bar creationCreating the progressBar instance upfront with the formatted message improves code clarity and maintainability.
68-74: Improved decorator implementationThe simplified decorator function is more efficient as it now directly returns the stored message from the progressBar instance, avoiding lock contention and map lookups during rendering.
86-87: Consistent state managementStoring the new progressBar instance in the map improves code consistency and thread safety.
This pull request improves the functionality and efficiency of the
ProgressBarimplementation ininternal/pb/pb.go. The key changes include adding a refresh rate to the progress bar, simplifying the creation of new bars, and improving thread safety by consolidating bar initialization logic.Enhancements to ProgressBar functionality:
timeimport to support the new refresh rate configuration for the progress bar.NewProgressBarfunction to set a refresh rate of 300 milliseconds for the progress bar usingmpbv8.WithRefreshRate.Simplification and thread safety improvements:
Addmethod to introduce aprogressBarinstance (newBar) earlier, consolidating the initialization of the bar and its associated metadata (e.g.,msg). This simplifies the logic and reduces redundant code.progressBarinstance in theAddmethod with the pre-initializednewBar, ensuring consistency and thread safety.Closes #160.
Summary by CodeRabbit