Repository navigation
perf(web): memoize current week hours and fix forecast cache invalidation - #35
Merged
Merged
Conversation
…tion Inspired by pingdotgg/t3code#10118, pingdotgg/t3code#20860, pingdotgg/t3code#17123. - Invalidate getCompletionForecast cache on holiday updates by including holidays version in key - Memoize getCurrentWeekHours keyed by entries version and Monday date string - Eliminate redundant array copy and sort in reports summary pack by indexing known sorted bounds
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getCompletionForecastinsrc/store.jsrelies onthis.state.holidaysfor its workday exclusion simulation, but omittedthis.getResourceVersion('holidays')fromforecastCacheKey. When holidays were created, edited, or synced, the forecast cache served stale projections until entries or config changed.getCurrentWeekHourswas computed repeatedly on dashboard renders without memoization, filtering and parsing dates across all entries every time.src/pages/reports.js: renderSummaryPack,store.getAllEntriesWithDerivedStatus()was cloned and re-sorted ascending just to extract the earliest and latest date bounds. SincegetAllEntriesWithDerivedStatus()is already sorted descending, sorting was completely redundant.Mechanism
this.getResourceVersion('holidays')toforecastCacheKeyinsrc/store.js.getCurrentWeekHours(now = new Date())keyed by${entriesVersion}:${mondayStr}so it caches across renders while automatically invalidating on entry modifications or weekly midnight rollover.reports.js: renderSummaryPack, extract date bounds directly viaentries[entries.length - 1]?.date(dateFrom) andentries[0]?.date(dateTo), eliminating array cloning and O(N log N) sorting.src/store-forecast.test.js.Upstream Inspiration
Before / After Numbers
npm test: 126/126 tests passing (5-run median: 570.23 ms).npm run build: Vite build passes in ~1.84s.renderSummaryPack: O(1) date bounds extraction instead of O(N log N) re-sort and clone.getCurrentWeekHours: O(1) cached lookup during dashboard renders.Risk
Very Low. Cache keys explicitly track resource versions and midnight calendar week transitions.