Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #2257 cache store url and enchance by_url scope #2262

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

LengTech11
Copy link
Collaborator

@LengTech11 LengTech11 commented Jan 13, 2025

Explanation of by_url Scope Override

The by_url scope in store_decorator.rb has been optimized for performance and flexibility:

Caching:

  • Results are cached for 1 hour to reduce database queries.
  • The cache key is based on the provided URL.

Exact and Partial Match:

  • The scope first tries to find an exact match for the URL.
  • If no exact match is found, it falls back to searching for a partial match.

Default Store:

  • If the URL is nil or empty, the scope will return the default store.

@LengTech11 LengTech11 requested a review from channainfo January 13, 2025 11:01
@LengTech11 LengTech11 self-assigned this Jan 13, 2025
@LengTech11 LengTech11 added enhancement New feature or request XS A few hours to make it ready labels Jan 13, 2025
@LengTech11 LengTech11 linked an issue Jan 13, 2025 that may be closed by this pull request
@LengTech11 LengTech11 force-pushed the 2257-enchance-spree-store branch from ab3058e to f69b8c3 Compare January 13, 2025 11:13
base.scope :by_url, lambda { |url|
Rails.cache.fetch("store_by_url_#{url}", expired_in: 1.hour) do
if url.present?
store = find_by('url = ?', url) || where('url like ?', "%#{url}%").first
Copy link
Owner

Choose a reason for hiding this comment

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

Just use one statement.

where('url = ? OR url like ?', url, "%#{url}%").first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request XS A few hours to make it ready
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

Enhance Spree store
2 participants