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

Replace cache_key_for_taxons with cache #1688

Merged
merged 2 commits into from
Jan 25, 2017

Conversation

jhawthorn
Copy link
Contributor

@jhawthorn jhawthorn commented Jan 19, 2017

Rails 5.0 supports generating a cache key from a scope, using a similar technique to what cache_key_for_taxons was using. This commit deprecates cache_key_for_taxons favour of using cache with a scope directly.

Passing a scope or collection to cache will generate a hash based on the scope and MAX(updated_at) and COUNT(*). This is better than the existing helper because it takes the full scope into account and finds the max_updated_at and count values in a single query.

I'd like to have done the same for cache_key_for_products, but can't because that query is constantly changing due to querying on available_on <= Time.current. I may investigate rounding this timestamp for a different PR.

Rails 5.0 supports generating a cache key from a scope, using a similar
technique to what cache_key_for_taxons was using. This commit
deprecates cache_key_for_taxons favour of using cache with a scope
directly.

Passing a scope or collection to `cache` will generate a hash based on
the scope and MAX(updated_at) and COUNT(*). This is better than the
existing helper because it takes the full scope into account and finds
the max_updated_at and count values in a single query.
Copy link
Member

@gmacdougall gmacdougall left a comment

Choose a reason for hiding this comment

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

👍

Thanks John.

Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Nice!

@jhawthorn jhawthorn merged commit 33797b4 into solidusio:master Jan 25, 2017
@jhawthorn jhawthorn deleted the taxons_cache_key branch January 25, 2017 23:55
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.

5 participants