Skip to content

Conversation

@UnbornAztecKing
Copy link
Contributor

@UnbornAztecKing UnbornAztecKing commented Jan 16, 2026

Summary

  • Eliminate redundant DateTime.toISO() calls by pre-computing ISO string timestamps once during CandlesGenerator initialization.
  • Refactor getCandle to use optional chaining, simplifying cache lookup logic.
  • Minor cleanups: remove intermediate variable blockCandleUpdatesMap from updateCandles scope, inline perpetualMarkets lookup.

Details

Performance optimization:

  • Add resolutionStartTimesISO: Map<CandleResolution, string> field to cache ISO timestamp strings alongside the existing resolutionStartTimes map.
  • Update all candle create/update methods to accept pre-computed startedAtISO: string instead of DateTime objects, removing 10+ .toISO() calls per block.
  • Pass pre-computed ISO strings to getOpenInterestMap to avoid repeated conversions in tight loops.

Code simplification:

  • Replace conditional cache lookup in getCandle with optional chaining: candlesMap[ticker]?.[resolution].
  • Move blockCandleUpdatesMap generation inline in createOrUpdatePostgresCandles to clarify data flow.
  • Extract perpetualMarkets array and perpetualMarketTickers to avoid repeated map value retrievals.

Risk & Impact

Low risk: internal refactor with no behavior change.

  • Optimization reduces string allocations and toISO() overhead during candle generation for each block.
  • No changes to public APIs, database schema, or Kafka message formats.
  • Logic remains functionally equivalent; only representation and timing of ISO conversion changes.

Testing

No new tests added; existing coverage reused.
Deployed to testnet and internal-mainnet.

@UnbornAztecKing UnbornAztecKing requested a review from a team as a code owner January 16, 2026 00:54
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Refactors candle start time representation from DateTime objects to ISO strings throughout the candles generator, consolidates BlockCandleUpdatesMap generation into createOrUpdatePostgresCandles, and updates method signatures to propagate ISO-based time usage consistently.

Changes

Cohort / File(s) Summary
Candle Cache Simplification
indexer/services/ender/src/caches/candle-cache.ts
Simplifies getCandle method to use optional chaining instead of explicit presence check, reducing conditional branches.
Candle Generator Time Format Migration
indexer/services/ender/src/lib/candles-generator.ts
Adds resolutionStartTimesISO cache, transitions DateTime to ISO string representation across candle creation/update flow. Moves BlockCandleUpdatesMap generation into createOrUpdatePostgresCandles. Updates createCandleInPostgres, createEmptyCandleInPostgres, and getOpenInterestMap signatures to accept/use ISO strings. Changes perpetualMarketTickers parameter handling in getOpenInterestMap.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #2839: Precomputes per-resolution candle start times; this PR extends that work by caching ISO string versions and refactoring dependent logic.
  • PR #1887: Modifies createCandleInPostgres and createEmptyCandleInPostgres signatures; this PR updates those same methods to use ISO string parameters.
  • PR #2441: Modifies candle-generation logic in candles-generator.ts; overlaps with this refactoring's reorganization of the candle creation flow.

Suggested labels

indexer

Suggested reviewers

  • shrenujb
  • tqin7

Poem

🐰 Hop through time zones with grace,
DateTime becomes ISO's embrace,
Strings replace objects with delight,
Candles glow with ISO's light!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
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.
Description check ❓ Inconclusive The PR description follows the template structure with Changelist, Test Plan, and Author/Reviewer Checklist sections; however, all checklist items remain unchecked with no labels manually added despite the PR containing significant changes. Review and check applicable checklist items. Consider if this PR warrants labels like 'refactor' or 'chore', and verify whether it requires 'indexer-postgres-breaking' or other relevant labels before merging.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: performance optimization via precomputed ISO strings and simplification of the getCandle method logic.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@UnbornAztecKing UnbornAztecKing merged commit 19d46af into main Jan 16, 2026
33 checks passed
@UnbornAztecKing UnbornAztecKing deleted the candles-performance-20260115 branch January 16, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants