Try to save actions as unique even when the store doesn't support it #1039
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 PR changes how we save unique actions in an attempt to at least partially address the issue reported in #1023.
The problem with the Hybrid Store and unique actions is that it doesn't support the atomic operation that would be necessary for guaranteeing uniqueness -- we can't write-lock the store for everyone else, check whether an action exists, and if it doesn't insert a new action, and then free the lock. It's not a relational database.
When saving unique actions, we currently ask the store whether it supports saving unique actions or not. If it doesn't we just save the action. So if the Hybrid Store is active (e.g., because we switch to it every time a plugin is disabled) saving a unique action is downgraded to just a regular save. This way it's possible to have many, many actions scheduled that should have been a single unique one.
So as we cannot guarantee uniqueness, we just insert.
This PR changes the strategy to check for an existing pending action and only inserts if none is found. As the Hybrid Store doesn't provide atomic operations, this is a best-effort strategy rather than a guaranteed uniqueness constraint.
The consequence should be that, in practice, a lot fewer duplicate actions should be generated than previously.
To test, check out this branch, step back a commit, and run the tests -- they'll fail as I have introduced a test that expects the Hybrid Store to support uniqueness. Then checkout this branch again, adding back the commit that changes the strategy. Run the tests again -- they should now pass.
Or, in other words:
git checkout update/try-unique-action-hybrid-store
npm install
// will update package-lock.json, please ignore update version in package-lock.json #1038composer install
git checkout ad63d64
composer run test
// this should fail 🔴git switch -
composer run test
// this should succeed 🟢