Skip to content

Fix the shop caching!!#1654

Merged
3kh0 merged 3 commits intohackclub:mainfrom
skyfallwastaken:fix-shop-caching
Mar 11, 2026
Merged

Fix the shop caching!!#1654
3kh0 merged 3 commits intohackclub:mainfrom
skyfallwastaken:fix-shop-caching

Conversation

@skyfallwastaken
Copy link
Member

Changes

  • Single cache fetch: Controller now calls cached_shop_page_data once and destructures both buyable_standalone and recently_added from the result, eliminating a redundant double-fetch of the same cache blob per request.
  • No duplicate cache data: recently_added is now filtered in-memory from the buyable_standalone array instead of running a separate DB query, reducing cache payload size.
  • Cleaned up redundant includes: Removed :record from includes(image_attachment: [:blob, :record]) since it refers back to the already-loaded ShopItem.
  • Renamed cache methods: invalidate_buyable_standalone_cacheinvalidate_shop_page_cache to accurately reflect the broader scope of the cache key.

Copilot AI review requested due to automatic review settings March 7, 2026 12:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors shop-page caching so the controller reads a single cached payload per request and derives “recently added” items from the already-cached buyable items, reducing redundant cache fetches and avoiding an extra query.

Changes:

  • Replace cached_buyable_standalone with cached_shop_page_data that returns both buyable_standalone and recently_added.
  • Compute recently_added in-memory from the cached buyable_standalone list to reduce cache/query duplication.
  • Rename cache invalidation to invalidate_shop_page_cache / invalidate_shop_page_cache! and simplify ActiveStorage includes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/models/shop_item.rb Introduces a unified shop-page cache payload and renames the cache key + invalidation methods.
app/controllers/shop_controller.rb Updates shop item loading to use the unified cached payload (single fetch) and uses cached “recently added”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@3kh0 3kh0 added this pull request to the merge queue Mar 11, 2026
Merged via the queue into hackclub:main with commit e2d9bab Mar 11, 2026
5 checks passed
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.

3 participants