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

Remove unused version_year from script cache key #32851

Merged
merged 3 commits into from Jan 24, 2020

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Jan 24, 2020

Fixes a bug introduced in #22887 where scripts fetched for a non-nil version_year (which included all fetches from ScriptLevelsController#show) were not pre-loaded during application initialization. This caused the first request (within each process) to ScriptLevelsController#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.

Copy link
Member

@davidsbailey davidsbailey left a 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:

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)
Copy link
Member

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.
Copy link
Member

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.

@davidsbailey
Copy link
Member

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

Oops, bad example, because frozen is a HOC script. but course1 is not, so I would have expected this test to have been failing:

test "should get show of course1 level 1 twice" do
assert_cached_queries(0) do
get '/s/course1/stage/3/puzzle/1'
end
assert_response :success
end

@davidsbailey
Copy link
Member

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.

Fixes regression in preloading scripts on initialization.
Copy link
Contributor

@maddiedierker maddiedierker left a 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!

@wjordan
Copy link
Contributor Author

wjordan commented Jan 24, 2020

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.

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).

@wjordan wjordan merged commit 41e07d0 into staging Jan 24, 2020
@wjordan wjordan deleted the script_cache_version_fix branch January 24, 2020 19:04
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.

None yet

3 participants