Skip to content

Use cache duration constants for query and LRU caches#429

Merged
Producdevity merged 5 commits into
stagingfrom
chore/cache-duration-constants
Jun 4, 2026
Merged

Use cache duration constants for query and LRU caches#429
Producdevity merged 5 commits into
stagingfrom
chore/cache-duration-constants

Conversation

@Producdevity

@Producdevity Producdevity commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Description

Expands CACHE_DURATIONS with the cache lifetimes already used throughout the app and replaces direct ms.* or millisecond literals in React Query cache options and LRU cache TTLs.

Fixes #398

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor
  • Other (please describe):

How Has This Been Tested?

  • Local build
  • Lint
  • Typecheck
  • Unit tests
  • Manual testing

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.ts
  • node_modules/.bin/tsc --noEmit --pretty false was attempted but is blocked by an existing SegaSaturnIcon.png module declaration resolution error unrelated to this refactor.

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I have checked that all checks (lint, typecheck, test) pass

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

  • Refactor
    • Centralized cache duration and polling presets (added VERY_SHORT, LOOKUP, LOOKUP_GC, STATIC, STATIC_GC; SHORT changed to 30s) and introduced shared polling intervals.
    • Result: unified caching and polling across the app — listings, admin stats, badges, lookups, image selectors, and related UI will refresh more consistently and often.

@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
emuready Ready Ready Preview, Comment Jun 4, 2026 6:44pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eeefe733-fa26-4a1d-a090-753b92639da0

📥 Commits

Reviewing files that changed from the base of the PR and between dd0d7d1 and 692466a.

📒 Files selected for processing (8)
  • src/app/admin/AdminLayoutClient.tsx
  • src/app/admin/api-access/components/AdminApiAccessPanel.tsx
  • src/app/admin/api-access/components/DeveloperApiAccessPanel.tsx
  • src/app/admin/components/ApprovalCountBadge.tsx
  • src/app/admin/pc-listing-approvals/page.tsx
  • src/app/listings/[id]/components/EditListingButton.tsx
  • src/app/pc-listings/[id]/components/EditPcListingButton.tsx
  • src/data/constants.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/admin/AdminLayoutClient.tsx

Walkthrough

This 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.

Changes

Cache Duration Consolidation

Layer / File(s) Summary
Expand CACHE_DURATIONS constant
src/data/constants.ts
CACHE_DURATIONS expands with new presets (VERY_SHORT, LOOKUP, LOOKUP_GC, STATIC, STATIC_GC); SHORT changed to 30s; POLLING_INTERVALS presets updated.
TRPC provider defaults
src/lib/api.tsx
QueryClient defaultOptions.queries staleTime/gcTime now use CACHE_DURATIONS.SHORT/CACHE_DURATIONS.MEDIUM.
Admin and approval components
src/app/admin/...
Admin layout, approval badge, API access panels, and related admin components now use CACHE_DURATIONS and POLLING_INTERVALS for staleTime/refetchInterval instead of hardcoded values.
Listings pages and filters
src/app/listings/..., src/app/pc-listings/..., src/app/listings/components/filters/*
Lookup data and preference caching switch from inline ms() durations to corresponding CACHE_DURATIONS constants.
New listing pages & game search
src/app/listings/new/*, src/app/games/new/search/hooks/useGameSearch.ts
Driver version and existing-game checks now use CACHE_DURATIONS for staleTime.
Home, profile, V2, retrocatalog
src/app/home/*, src/app/profile/*, src/app/v2/listings/*, src/components/retrocatalog/*
Device/SOC lookup and user preference queries use CACHE_DURATIONS instead of ms durations.
Image selector providers
src/components/ui/image-selectors/providers/*
IGDB/RAWG/TGDB image search queries use CACHE_DURATIONS.MEDIUM for staleTime.
Server cache instances
src/server/utils/cache/instances.ts
Server LRU caches and exported cache instances replace TIME_CONSTANTS and inline durations with CACHE_DURATIONS values; some max adjustments retained.
Repositories, TGDB & batchers
src/server/repositories/devices.repository.ts, src/server/tgdb.ts, src/server/utils/steamGameBatcher.ts
Trending devices, TGDB platforms, and Steam batcher cache TTLs now use CACHE_DURATIONS constants.
Driver versions & game search
src/server/utils/driver-versions.ts, src/server/utils/{steamGameSearch,switchGameSearch,threeDsGameSearch}.ts
Driver fetch paths and various game-search caches adopt CACHE_DURATIONS TTLs.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and concisely describes the main refactoring objective of centralizing cache duration constants across the codebase.
Description check ✅ Passed Description includes issue reference, change type (Refactor), testing results (Lint passed), and comprehensive checklist with notes for reviewers.
Linked Issues check ✅ Passed PR addresses issue #398 by systematically replacing inline ms() calls and millisecond literals with CACHE_DURATIONS constants across 33+ files.
Out of Scope Changes check ✅ Passed All changes are directly related to centralizing cache duration constants; non-cache timing values (polling intervals, retry delays, rate limits) were intentionally excluded.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cache-duration-constants
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch chore/cache-duration-constants

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/server/utils/cache/instances.ts (1)

75-78: ⚡ Quick win

Default TTL inconsistent with actual usage.

The default ttl: CACHE_DURATIONS.LONG (15 minutes) is never used in practice. Context from src/server/tgdb.ts shows that getPlatforms() always overrides this with { ttl: CACHE_DURATIONS.EXTRA_LONG } (1 hour) when setting cache entries.

Consider aligning the default to CACHE_DURATIONS.EXTRA_LONG to 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

📥 Commits

Reviewing files that changed from the base of the PR and between cd4e914 and 9adfe3d.

📒 Files selected for processing (26)
  • src/app/admin/AdminLayoutClient.tsx
  • src/app/admin/components/ApprovalCountBadge.tsx
  • src/app/games/new/search/hooks/useGameSearch.ts
  • src/app/home/components/HomeTrendingDevices.tsx
  • src/app/listings/ListingsPage.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/data/constants.ts
  • src/lib/api.tsx
  • src/server/repositories/devices.repository.ts
  • src/server/utils/cache/instances.ts
  • src/server/utils/driver-versions.ts
  • src/server/utils/steamGameSearch.ts
  • src/server/utils/switchGameSearch.ts
  • src/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,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

fix the refetchInterval as well. this should be done pretty much everywhere as well.

Comment thread src/data/constants.ts Outdated
export const CACHE_DURATIONS = {
SHORT: ms.minutes(1),
VERY_SHORT: ms.seconds(10),
SHORT: ms.seconds(30),

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

short can be 1 minute

@Producdevity Producdevity merged commit 30b57c8 into staging Jun 4, 2026
8 checks passed
@Producdevity Producdevity deleted the chore/cache-duration-constants branch June 4, 2026 19:12
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.

chore: use CACHE_DURATIONS constant wherever possible instead of inline ms() calls

1 participant