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
Remove unused version_year from script cache key #32851
Conversation
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.
Thank you, @wjordan ! Looks great.
While you are in here, you could also delete the unused get_script_family_redirect
if you want -- nothing references it, so it should be pretty low risk.
The only other thing I can think of would be to add an integration test which counts the number of database requests. However, it looks like we already have some which do that, so I'm a bit puzzled as to why those haven't been failing:
code-dot-org/dashboard/test/integration/caching_test.rb
Lines 22 to 27 in 06d2450
test "should get show of frozen level 1" do | |
assert_cached_queries(0) do | |
get '/s/frozen/stage/1/puzzle/1' | |
end | |
assert_response :success | |
end |
# Populate cache on miss. | ||
script_cache[cache_key] = get_without_cache(id_or_name, version_year: version_year) | ||
script_cache[cache_key] = get_without_cache(id_or_name) |
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.
looks like cache_key needs to be defined and must be a string
# For example: | ||
# get_from_cache('11') --> script_cache['11'] = <Script id=11, name=...> | ||
# get_from_cache('frozen') --> script_cache['frozen'] = <Script name="frozen", id=...> | ||
# get_from_cache('csp1') --> script_cache['csp1'] = <Script redirect_to="csp1-2018"> | ||
# get_from_cache('csp1', version_year: '2017') --> script_cache['csp1/2017'] = <Script redirect_to="csp1-2017"> | ||
# | ||
# @param id_or_name [String|Integer] script id, script name, or script family name. |
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.
this should just be script id or script name.
Oops, bad example, because frozen is a HOC script. but course1 is not, so I would have expected this test to have been failing: code-dot-org/dashboard/test/integration/caching_test.rb Lines 80 to 85 in 06d2450
|
ok... looks like those tests take a cache miss the first time, and are only measuring the db query count on the second try. so a different kind of test would be needed in order to test that this PR eliminates the slow startup problem that we're trying to address. |
693dbf0
to
f6b5732
Compare
Fixes regression in preloading scripts on initialization.
f6b5732
to
b38e88b
Compare
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.
🥇 thank you for this, will!
Yeah, for covering this particular issue we need to test that the caching-initialization behavior has already cached the script on the very first request, not the second. I've added a test to cover this in 9a0326f (and confirmed the test failed before this PR and passes with the fix). |
Fixes a bug introduced in #22887 where scripts fetched for a non-nil
version_year
(which included all fetches fromScriptLevelsController#show
) were not pre-loaded during application initialization. This caused the first request (within each process) toScriptLevelsController#show
for each script to be slower than expected on startup.Since #28683,
version_year
is no longer used by the script-cache fetch anyway, so all of the logic extending the cache key by this variable can be removed for simplicity.