-
Notifications
You must be signed in to change notification settings - Fork 0
fix: batch insert db by max postgres limit #20
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
Conversation
WalkthroughThe changes add a constant Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Bulk as BulkInsert Function
participant DB as Database
App->>Bulk: Call BulkInsert(columns, values)
activate Bulk
Bulk->>Bulk: Compute max rows per batch (MaxPostgresParams / numColumns)
loop For each batch of rows
Bulk->>DB: Execute batch insert query
DB-->>Bulk: Return result
end
Bulk-->>App: Return success or error
deactivate Bulk
Poem
✨ Finishing Touches
🪧 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 (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
informative-indexer/db/util.go (1)
83-83
: Add safety checks for the batch size calculation.The current implementation could benefit from additional safety checks:
- Verify that
maxRowsPerBatch
is at least 1 to prevent infinite loops- Guard against potential integer overflow in the division
Consider applying this improvement:
-maxRowsPerBatch := MaxPostgresParams / len(columns) +if len(columns) > MaxPostgresParams { + return fmt.Errorf("too many columns: %d exceeds maximum allowed parameters", len(columns)) +} +maxRowsPerBatch := MaxPostgresParams / len(columns) +if maxRowsPerBatch < 1 { + maxRowsPerBatch = 1 +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
informative-indexer/db/util.go
(2 hunks)
🔇 Additional comments (2)
informative-indexer/db/util.go (2)
14-16
: LGTM! Well-defined constant for PostgreSQL parameter limit.Using
math.MaxUint16
(65535) as the maximum parameter limit is correct and follows PostgreSQL's specifications.
83-100
: LGTM! Effective implementation of batch processing.The batching logic correctly handles PostgreSQL's parameter limit while maintaining clean error handling and efficient slice operations.
Summary by CodeRabbit