Skip to content

Conversation

@domhhv
Copy link
Owner

@domhhv domhhv commented Jan 30, 2026

Skip redundant API calls when navigating from a wider range (month) to a narrower one (week/day) by tracking the last fetched range and checking containment before fetching. occurrences are re-indexed in memory on cache hit; notes skip the fetch entirely. mutations invalidate the cache.

Summary by CodeRabbit

  • Performance Improvements

    • Added smart caching for notes and occurrences data, reducing unnecessary server requests when reviewing previously loaded date ranges.
  • Bug Fixes

    • Improved timezone handling for date operations to ensure consistent accuracy across different time zones.

✏️ Tip: You can customize this high-level summary in your review settings.

Skip redundant API calls when navigating from a wider range (month) to a
narrower one (week/day) by tracking the last fetched range and checking
containment before fetching. occurrences are re-indexed in memory on
cache hit; notes skip the fetch entirely. mutations invalidate the cache.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

The PR introduces range-based caching for notes and occurrences. It updates the notes service to use ZonedDateTime with absolute string formatting, and modifies both notes and occurrences stores to track fetched date ranges and bypass API calls when requested ranges fall within cached data.

Changes

Cohort / File(s) Summary
Notes Service Date Types
src/services/notes.service.ts
Updated listNotes to accept ZonedDateTime parameters instead of CalendarDateTime and changed date formatting from toString() to toAbsoluteString() for database queries.
Notes Store Caching
src/stores/notes.store.ts
Added notesFetchedRange field to cache loaded note ranges; fetchNotes now checks cache before fetching and skips API calls for cached ranges; implemented cache invalidation on mutations (addNote, clearNotes, deleteNote, updateNote); updated date handling to use toZoned with getLocalTimeZone().
Occurrences Store Caching
src/stores/occurrences.store.ts
Added occurrencesFetchedRange field to track cached date ranges; enhanced fetchOccurrences with cache logic that rebuilds occurrencesByDate locally from existing data when requested range is fully covered by cache, avoiding API calls; implemented cache invalidation on mutations (addOccurrence, clearOccurrences, removeOccurrence, updateOccurrence).

Sequence Diagram(s)

sequenceDiagram
    participant Component
    participant Store as Notes/Occurrences Store
    participant Cache as Cached Range
    participant Service as Notes/Occurrences Service
    participant API as Backend API

    rect rgba(173, 216, 230, 0.5)
    note over Component,API: Cached Path
    Component->>Store: fetchNotes/fetchOccurrences(range)
    Store->>Cache: Check if range covered?
    Cache-->>Store: Yes, cached
    Store->>Store: Rebuild from existing state
    Store-->>Component: Return cached data
    end

    rect rgba(255, 182, 193, 0.5)
    note over Component,API: Cache Miss Path
    Component->>Store: fetchNotes/fetchOccurrences(range)
    Store->>Cache: Check if range covered?
    Cache-->>Store: No, not cached
    Store->>Service: listNotes/listOccurrences(zoned range)
    Service->>API: Query with absolute date strings
    API-->>Service: Return results
    Service-->>Store: Results
    Store->>Cache: Update notesFetchedRange/occurrencesFetchedRange
    Store-->>Component: Return fresh data
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hop, hop, time's in zones!
Cache those ranges, save API bones,
Zoned dates now flow, absolute strings glow,
Fetch once, store it, reuse the data—
Smart hopping through time's data! 🕐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: implementing client-side caching for calendar data (occurrences and notes) based on fetched date ranges.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/cache-calendar-range-fetches

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


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.

@relativeci
Copy link

relativeci bot commented Jan 30, 2026

#196 Bundle Size — 1.84MiB (+0.04%).

47ea7b5(current) vs 1dbb671 main#195(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#196
     Baseline
#195
Regression  Initial JS 1.09MiB(+0.07%) 1.09MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 87.13% 87.12%
No change  Chunks 8 8
No change  Assets 9 9
No change  Modules 6676 6676
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 223 223
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#196
     Baseline
#195
Regression  JS 1.61MiB (+0.05%) 1.6MiB
No change  CSS 242.77KiB 242.77KiB

Bundle analysis reportBranch feat/cache-calendar-range-fetche...Project dashboard


Generated by RelativeCIDocumentationReport issue

@domhhv domhhv merged commit f7433df into main Jan 30, 2026
11 checks passed
@domhhv domhhv deleted the feat/cache-calendar-range-fetches branch January 30, 2026 12:18
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.

2 participants