-
Notifications
You must be signed in to change notification settings - Fork 46
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
Moving ContentBlock methods #1853
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jeremyf
force-pushed
the
jeremyf---extracting-common-logic
branch
from
November 30, 2022 20:42
9320fee
to
aa71d7e
Compare
kirkkwang
requested changes
Nov 30, 2022
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.
just the one extra space
spec/models/content_block_spec.rb
Outdated
describe '.block_for' do | ||
subject { described_class.block_for(name: block_name, fallback_value: given_fallback_value) } | ||
|
||
let(:block_name) { "blocky.mc.blockface" } |
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.
Remove extra space
let(:block_name) { "blocky.mc.blockface" }
looks like this getting flagged in CI
jeremyf
force-pushed
the
jeremyf---extracting-common-logic
branch
from
December 1, 2022 13:53
aa71d7e
to
26b7051
Compare
kirkkwang
previously approved these changes
Dec 1, 2022
jeremyf
force-pushed
the
jeremyf---extracting-common-logic
branch
from
December 13, 2022 22:14
26b7051
to
ac18d2d
Compare
Prior to this commit there were two very similar chunks of code regarding `ContentBlock.block_for` type logic. With this commit, those chunks of code are consolidated. Why the consolidation? There's an opportunity to more aggressively cache those values. At present, looking at the logs there are numerous singular queries of the ContentBlock structure. (See the details block below) Through this consolidation we can now more easily introduce a caching and invalidation layer. One possible caching mechanism would be on initial query to load all named blocks into an in memory array; then when we update the block we invalidate the in-memory array. The present logging does not provide insight into the cost of each of those individual queries but that is a lot of query calls (which ActiveRecord caches). <details> <summary>Content Blog Log Query</summary> ``` ContentBlock Load (0.6ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "body_font"], ["LIMIT", 1]] CACHE ContentBlock Load (0.1ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "body_font"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "body_font"], ["LIMIT", 1]] ContentBlock Load (0.3ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "headline_font"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "link_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "link_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "link_hover_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "link_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "footer_link_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "footer_link_hover_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "header_background_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "header_text_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "header_background_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "searchbar_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "searchbar_background_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "searchbar_text_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "searchbar_text_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "searchbar_background_hover_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "searchbar_text_hover_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "active_tabs_background_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "primary_button_background_color"], ["LIMIT", 1]] ContentBlock Load (0.6ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_background_color"], ["LIMIT", 1]] ContentBlock Load (0.3ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_border_color"], ["LIMIT", 1]] ContentBlock Load (0.3ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_text_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_border_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_border_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_border_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_border_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "default_button_border_color"], ["LIMIT", 1]] ContentBlock Load (0.3ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "facet_panel_text_color"], ["LIMIT", 1]] ContentBlock Load (0.2ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "facet_panel_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "facet_panel_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "facet_panel_background_color"], ["LIMIT", 1]] CACHE ContentBlock Load (0.0ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "facet_panel_text_color"], ["LIMIT", 1]] ContentBlock Load (0.4ms) SELECT "content_blocks".* FROM "content_blocks" WHERE "content_blocks"."name" = $1 LIMIT $2 [["name", "custom_css_block"], ["LIMIT", 1]] Rendered shared/_appearance_styles.html.erb (52.2ms) ``` </details>
jeremyf
force-pushed
the
jeremyf---extracting-common-logic
branch
from
December 14, 2022 15:45
ac18d2d
to
47847c3
Compare
laritakr
approved these changes
Dec 14, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prior to this commit there were two very similar chunks of code regarding
ContentBlock.block_for
type logic.With this commit, those chunks of code are consolidated.
Why the consolidation? There's an opportunity to more aggressively cache those values.
At present, looking at the logs there are numerous singular queries of the ContentBlock structure. (See the details block below)
Through this consolidation we can now more
easily introduce a caching and invalidation layer.
One possible caching mechanism would be on initial query to load all named blocks into an in memory array; then when we update the block we invalidate the in-memory array.
The present logging does not provide insight into the cost of each of those individual queries but that is a lot of query calls (which ActiveRecord caches).
Content Blog Log Query
@samvera/hyku-code-reviewers