Skip to content

Refactor ScriptHelper class to be thread-safe#10304

Merged
mitchellhenke merged 3 commits intomainfrom
mitchellhenke/thread-safe-script-helper
Mar 25, 2024
Merged

Refactor ScriptHelper class to be thread-safe#10304
mitchellhenke merged 3 commits intomainfrom
mitchellhenke/thread-safe-script-helper

Conversation

@mitchellhenke
Copy link
Contributor

🛠 Summary of changes

Builds on #10301 to make ScriptHelper explicitly thread-safe as well using RequestStore. The current usage is not necessarily thread-unsafe, but this refactors it to use the thread-safe RequestStore to protect against future changes that may not be.

@mitchellhenke mitchellhenke requested a review from a team March 25, 2024 18:00
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

@mitchellhenke mitchellhenke Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 14f47f599a

Comment on lines 11 to 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this would be a good case to use the .fetch API from the gem?

Suggested change
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))

Copy link
Contributor Author

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?

Copy link
Contributor

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

@mitchellhenke mitchellhenke force-pushed the mitchellhenke/thread-safe-asset-sources branch from 31a899c to 53d2123 Compare March 25, 2024 18:27
Base automatically changed from mitchellhenke/thread-safe-asset-sources to main March 25, 2024 18:57
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/thread-safe-script-helper branch from 14f47f5 to 8cb13d2 Compare March 25, 2024 20:09
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Mitchell Henke added 3 commits March 25, 2024 15:40
changelog: Internal, Performance, Refactor ScriptHelper class to be thread-safe
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/thread-safe-script-helper branch from d9fc7c3 to ee1ad6a Compare March 25, 2024 20:40
@mitchellhenke mitchellhenke merged commit 6d02f2e into main Mar 25, 2024
@mitchellhenke mitchellhenke deleted the mitchellhenke/thread-safe-script-helper branch March 25, 2024 20:59
mitchellhenke pushed a commit that referenced this pull request Mar 26, 2024
mitchellhenke pushed a commit that referenced this pull request Mar 26, 2024
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.

3 participants