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
4210 Fetch and scope variants for shop in ProductsRenderer only once #4224
4210 Fetch and scope variants for shop in ProductsRenderer only once #4224
Conversation
85d6a36
to
0138d07
Compare
Very good point. It's worth enabling Datadog's Ruby GC monitoring. According to https://docs.datadoghq.com/tracing/setup/ruby/ it will fetch Garbage collection statistics which will allow us to validate this claim. |
# because we need to look up the stock as overridden by | ||
# VariantOverrides, and the scope method is not affected by them. | ||
scoper = OpenFoodNetwork::ScopeVariantToHub.new(@distributor) | ||
@all_variants_for_shop = Spree::Variant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@all_variants_for_shop =
is redundant here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I missed that. Yeah, that shouldn't be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Sorry, that was from an earlier change. Fixed already.
Unfortunately, until we don't get rid of VariantOverrides we have a blocker to properly improve the performance of many endpoints and jobs. |
0138d07
to
590ce67
Compare
What? Why?
This caches in instance variable
ProductsRenderer#all_variants_for_shop
so that the variants do not have to be fetched and scoped twice for the two times that this method is called.This is a small code change that could considerably reduce the RAM and processing done for
RefreshProductsCacheJob
. It takes some time for Ruby garbage collection to happen, so for a shop that has thousands of variants in their order cycle, this could meannumber_of_variants + number_of_variant_overrides
fewer objects in memory, in addition to the I think only slightly reduced number of SQL queries.(Maybe garbage collection is something we could look into too, if we're not doing this already.)
What should we test?
For below:
Do the following with an open OC:
Release notes
ProductsRenderer
used inRefreshProductsCacheJob
only once.Changelog Category: Changed