module AutoConflictResolution
def store(stream_name = loaded_from_stream_name, event_store: default_event_store)
super
rescue
unpublished_events = unpublished_events()
tried_version = version
self.load(stream_name, event_store: event_store)
published_events = loaded_events[tried_version+1..version]
if not_conflicting(unpublished_events, published_events)
@unpublished_events = unpublished_events
store(stream_name: stream_name, event_store: event_store)
end
end
end
class OrderWithNonConflictingStore < Order
include AutoConflictResolution
private
def not_conflicting(unpublished_events, published_events)
true
end
end
could be optimized better to use RES to read all events on position >= tried_version+1 instead of reading all events again and selecting from array those conflicting ones.
Idea described here: https://github.com/RailsEventStore/aggregate_root/issues/8#issuecomment-325655544
This is a separate issue because it's a different idea than just handling concurrency properly.
The text was updated successfully, but these errors were encountered: