Skip to content

⚡ Bolt: optimize risk signals insertion in RiskRepository#23649

Merged
BrianCLong merged 1 commit intomainfrom
bolt-optimize-risk-repository-13584210523542231955
Apr 9, 2026
Merged

⚡ Bolt: optimize risk signals insertion in RiskRepository#23649
BrianCLong merged 1 commit intomainfrom
bolt-optimize-risk-repository-13584210523542231955

Conversation

@BrianCLong
Copy link
Copy Markdown
Owner

This PR implements a performance optimization in RiskRepository.ts to improve the efficiency of risk signal ingestion.

💡 What

  • Hoisted the default timestamp creation (new Date()) outside of the signal processing loops.
  • Removed the RETURNING * clause from the risk_signals batch INSERT query.
  • Eliminated the unused savedSignals array and the subsequent loop that was mapping database results to JavaScript objects.

🎯 Why

  • Reducing Allocation: In the previous implementation, a new Date object was instantiated for every signal without a detectedAt timestamp. For large batches (e.g., 100+ signals), this created unnecessary GC pressure.
  • Eliminating Redundant Work: The signals being inserted were being fetched back from the DB and mapped into objects that were never used, as the saveRiskScore method only returns the RiskScore object, not the signals.

📊 Impact

  • Memory Efficiency: Reduced heap allocations and GC frequency during signal-heavy ingestion.
  • Database Throughput: Reduced DB processing time and network payload by removing the RETURNING clause.
  • CPU Efficiency: Eliminated O(N) mapping loop after signal insertion.

🔬 Measurement

  • Verified via manual code inspection and node --check to ensure syntax validity.
  • Repository tests in server/src/db/repositories/__tests__/RiskRepository.test.ts should be run to confirm functional parity.

PR created automatically by Jules for task 13584210523542231955 started by @BrianCLong

- Hoisted default `new Date()` creation out of the batch loop to reduce redundant object allocations.
- Removed unnecessary `RETURNING *` clause and mapping loop for risk signals, as they are not used in the final return value of `saveRiskScore`.
- Reduced database overhead and application memory usage during high-volume risk signal ingestion.

Co-authored-by: BrianCLong <6404035+BrianCLong@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes the RiskRepository by hoisting the default timestamp creation for risk signals to avoid redundant object allocations during batched inserts. Additionally, it removes the RETURNING * clause and the subsequent mapping loop for inserted signals, as they are not required for the return value. I have no feedback to provide.

@BrianCLong BrianCLong merged commit 1978d28 into main Apr 9, 2026
30 of 41 checks passed
@BrianCLong BrianCLong deleted the bolt-optimize-risk-repository-13584210523542231955 branch April 9, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant