Use cache duration constants for query and LRU caches#429
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR replaces inline ms() calls and hardcoded millisecond durations with centralized CACHE_DURATIONS and POLLING_INTERVALS across client React Query options, provider defaults, and server cache TTLs. ChangesCache Duration Consolidation
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/server/utils/cache/instances.ts (1)
75-78: ⚡ Quick winDefault TTL inconsistent with actual usage.
The default
ttl: CACHE_DURATIONS.LONG(15 minutes) is never used in practice. Context fromsrc/server/tgdb.tsshows thatgetPlatforms()always overrides this with{ ttl: CACHE_DURATIONS.EXTRA_LONG }(1 hour) when setting cache entries.Consider aligning the default to
CACHE_DURATIONS.EXTRA_LONGto match actual usage and avoid confusion.Proposed alignment
export const tgdbPlatformsCache = new LRUCache<string, TGDBPlatformsResponse>({ - ttl: CACHE_DURATIONS.LONG, + ttl: CACHE_DURATIONS.EXTRA_LONG, max: 10, })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/utils/cache/instances.ts` around lines 75 - 78, The tgdbPlatformsCache default TTL is set to CACHE_DURATIONS.LONG but getPlatforms() always writes entries with { ttl: CACHE_DURATIONS.EXTRA_LONG }, causing inconsistency; update the tgdbPlatformsCache initialization to use ttl: CACHE_DURATIONS.EXTRA_LONG instead of CACHE_DURATIONS.LONG so the cache default matches actual usage (search for tgdbPlatformsCache, CACHE_DURATIONS.LONG/CACHE_DURATIONS.EXTRA_LONG and getPlatforms() to apply the change).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/server/utils/cache/instances.ts`:
- Around line 75-78: The tgdbPlatformsCache default TTL is set to
CACHE_DURATIONS.LONG but getPlatforms() always writes entries with { ttl:
CACHE_DURATIONS.EXTRA_LONG }, causing inconsistency; update the
tgdbPlatformsCache initialization to use ttl: CACHE_DURATIONS.EXTRA_LONG instead
of CACHE_DURATIONS.LONG so the cache default matches actual usage (search for
tgdbPlatformsCache, CACHE_DURATIONS.LONG/CACHE_DURATIONS.EXTRA_LONG and
getPlatforms() to apply the change).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7c927a01-f40e-49ba-953b-f63d329296d5
📒 Files selected for processing (26)
src/app/admin/AdminLayoutClient.tsxsrc/app/admin/components/ApprovalCountBadge.tsxsrc/app/games/new/search/hooks/useGameSearch.tssrc/app/home/components/HomeTrendingDevices.tsxsrc/app/listings/ListingsPage.tsxsrc/app/listings/components/filters/AsyncDeviceFilterSelect.tsxsrc/app/listings/components/filters/AsyncSocFilterSelect.tsxsrc/app/listings/components/shared/custom-fields/hooks/useDriverVersions.tssrc/app/listings/new/NewListingPage.tsxsrc/app/pc-listings/PcListingsPage.tsxsrc/app/pc-listings/components/filters/AsyncCpuFilterSelect.tsxsrc/app/pc-listings/components/filters/AsyncGpuFilterSelect.tsxsrc/app/pc-listings/new/NewPcListingPage.tsxsrc/app/profile/components/DeviceSelector.tsxsrc/app/profile/components/PcPresetModal.tsxsrc/app/profile/components/SocSelector.tsxsrc/app/v2/listings/V2ListingsPage.tsxsrc/components/retrocatalog/useRetroCatalogDevice.tssrc/data/constants.tssrc/lib/api.tsxsrc/server/repositories/devices.repository.tssrc/server/utils/cache/instances.tssrc/server/utils/driver-versions.tssrc/server/utils/steamGameSearch.tssrc/server/utils/switchGameSearch.tssrc/server/utils/threeDsGameSearch.ts
✅ Files skipped from review due to trivial changes (2)
- src/app/v2/listings/V2ListingsPage.tsx
- src/server/repositories/devices.repository.ts
🚧 Files skipped from review as they are similar to previous changes (15)
- src/app/listings/components/filters/AsyncDeviceFilterSelect.tsx
- src/app/profile/components/PcPresetModal.tsx
- src/app/listings/components/shared/custom-fields/hooks/useDriverVersions.ts
- src/app/profile/components/DeviceSelector.tsx
- src/app/profile/components/SocSelector.tsx
- src/server/utils/driver-versions.ts
- src/components/retrocatalog/useRetroCatalogDevice.ts
- src/app/home/components/HomeTrendingDevices.tsx
- src/app/listings/ListingsPage.tsx
- src/app/listings/components/filters/AsyncSocFilterSelect.tsx
- src/app/listings/new/NewListingPage.tsx
- src/app/pc-listings/new/NewPcListingPage.tsx
- src/lib/api.tsx
- src/app/pc-listings/PcListingsPage.tsx
- src/app/pc-listings/components/filters/AsyncGpuFilterSelect.tsx
|
|
||
| const listingStatsQuery = api.listings.stats.useQuery(undefined, { | ||
| enabled: canViewStats && props.href === '/admin/approvals', | ||
| refetchInterval: 30000, |
There was a problem hiding this comment.
fix the refetchInterval as well. this should be done pretty much everywhere as well.
| export const CACHE_DURATIONS = { | ||
| SHORT: ms.minutes(1), | ||
| VERY_SHORT: ms.seconds(10), | ||
| SHORT: ms.seconds(30), |
There was a problem hiding this comment.
short can be 1 minute
Description
Expands
CACHE_DURATIONSwith the cache lifetimes already used throughout the app and replaces directms.*or millisecond literals in React Query cache options and LRU cache TTLs.Fixes #398
Type of change
How Has This Been Tested?
Commands run:
node_modules/.bin/eslint src/app/admin/AdminLayoutClient.tsx src/app/admin/components/ApprovalCountBadge.tsx src/app/admin/title-id-tools/TitleIdTool.tsx src/app/games/new/search/hooks/useGameSearch.ts src/app/home/components/HomeTrendingDevices.tsx src/app/listings/ListingsPage.tsx 'src/app/listings/[id]/components/ViewConfigButton.tsx' src/app/listings/components/filters/AsyncDeviceFilterSelect.tsx src/app/listings/components/filters/AsyncSocFilterSelect.tsx src/app/listings/components/shared/custom-fields/hooks/useDriverVersions.ts src/app/listings/new/NewListingPage.tsx src/app/pc-listings/PcListingsPage.tsx src/app/pc-listings/components/filters/AsyncCpuFilterSelect.tsx src/app/pc-listings/components/filters/AsyncGpuFilterSelect.tsx src/app/pc-listings/new/NewPcListingPage.tsx src/app/profile/components/DeviceSelector.tsx src/app/profile/components/PcPresetModal.tsx src/app/profile/components/SocSelector.tsx src/app/v2/listings/V2ListingsPage.tsx src/components/retrocatalog/useRetroCatalogDevice.ts src/components/ui/image-selectors/providers/IGDBImageSelector.tsx src/components/ui/image-selectors/providers/RawgImageSelector.tsx src/components/ui/image-selectors/providers/TGDBImageSelector.tsx src/data/constants.ts src/lib/api.tsx src/server/repositories/devices.repository.ts src/server/tgdb.ts src/server/utils/cache/instances.ts src/server/utils/driver-versions.ts src/server/utils/steamGameBatcher.ts src/server/utils/steamGameSearch.ts src/server/utils/switchGameSearch.ts src/server/utils/threeDsGameSearch.tsnode_modules/.bin/tsc --noEmit --pretty falsewas attempted but is blocked by an existingSegaSaturnIcon.pngmodule declaration resolution error unrelated to this refactor.Screenshots (if applicable)
N/A
Checklist
Notes for reviewers
The lint command exits successfully but reports pre-existing React Compiler warnings in several touched files. This PR leaves non-cache timing values such as rate-limit windows, polling intervals, retry delays, and scheduled refresh intervals unchanged.
Summary by CodeRabbit