Retry PouchDB put operations if there's a conflict
If two updates to the same object arrive simultaneously, it's possible that the same _rev
value from the stored object will be copied onto both of them before either are saved; the second update to be saved will then throw a conflict error.
As pubsweet is doing last-write-wins without checking that the updates are in the correct order, a conflicting put
can be retried until it succeeds.
This requires that the updates are patch
operations (only containing the fields to be updated) rather than put
(containing the whole object), as otherwise data would be lost if the updates aren't processed in the correct order.
This is a temporary fix for an issue that would be better solved by either using the _rev
value as intended (to prevent conflicting updates) or moving to a different storage system.