Use create_or_find_by
to reduce activity status deadlocks
#4547
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.
This pull request replace
find_or_create_by
withcreate_or_find_by
to reduce the number of deadlocks.According to the docs:
I left in the single retry attempt because a deadlock is still possible if an activity_status is deleted:
To be able to use this method, I had to remove the rails unique validation. We already have a database unique index for this, which throws the expected error. I adjusted one test, to fix it and to make sure this error gets thrown.
I also had to change the method in the one other place where activity status are created to be able to handle these new unique errors.
See #1877 for some history on this issue.
Closes #4479