-
Notifications
You must be signed in to change notification settings - Fork 167
Refactor ScriptHelper class to be thread-safe #10304
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,13 @@ | ||||||||||||||||||
| # frozen_string_literal: true | ||||||||||||||||||
|
|
||||||||||||||||||
| # rubocop:disable Rails/HelperInstanceVariable | ||||||||||||||||||
| module ScriptHelper | ||||||||||||||||||
| def javascript_packs_tag_once(*names, **attributes) | ||||||||||||||||||
| @scripts = @scripts.to_h.merge(names.index_with(attributes)) | ||||||||||||||||||
| scripts = RequestStore.store[:scripts] | ||||||||||||||||||
| if scripts | ||||||||||||||||||
| RequestStore.store[:scripts].merge!(names.index_with(attributes)) | ||||||||||||||||||
| else | ||||||||||||||||||
| RequestStore.store[:scripts] = names.index_with(attributes) | ||||||||||||||||||
| end | ||||||||||||||||||
|
||||||||||||||||||
| if scripts | |
| RequestStore.store[:scripts].merge!(names.index_with(attributes)) | |
| else | |
| RequestStore.store[:scripts] = names.index_with(attributes) | |
| end | |
| RequestStore.fetch(:scripts) do | |
| names.index_with(attributes) | |
| end.merge!(names.index_with(attributes)) |
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.
I was trying to use it, but it felt not quite right to merge into itself in the empty case?
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.
prob fine to leave as-is
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,7 @@ class Analytics | |
| end | ||
|
|
||
| config.before(:each) do | ||
| RequestStore.clear! | ||
| Rails.cache.clear | ||
| end | ||
|
|
||
|
|
||
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.
request_store is only a transitive dependency of lograge, if we're using it directly like this, WDYT of making it an explicit dependency?
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.
Oops, yes, meant to do that
Uh oh!
There was an error while loading. Please reload this page.
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.
Added in 14f47f599a