Fix incorrect cache usage by available_properties (big cache use, slo… #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…w reads)
Spree::Filters::PropertyPresenter includes all ProductProperty for all Products, which can be very many. This would be serialized and stored in the cache by Rails.cache.fetch. As only uniq_values are actually relevant and being used, all the ProductProperty's should not be stored in cache. The number of these properties can be very significant (in the 1000s), taking up a lot of cache and making the cache read very slow (over 1 second with solid_cache).
This fixes two issues, which were for me quite big:
@damianlegawiec I'm not sure how this is handled with api v2, but you might want to check in case you use cache there. PropertyPresenter is not designed well to be cached directly, as it was being used now.
The solution could be better by redesigning Spree::Filters::PropertiesPresenter/PropertyPresenter, but I didn't want to fiddle too much with the core gem in this case.
I think the same issue could be there with OptionsPresenter, but I didn't have time to check that right now.
Also I think these available-properties cache entries are being created for product searches as well (each search term with its own cache key), which is probably a bad idea as it will eat up the cache space very quickly as well and the usefulness of that is very limited.