Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AggregateRoot::AutoConflictResolution #107

Closed
paneq opened this issue Sep 11, 2017 · 2 comments
Closed

AggregateRoot::AutoConflictResolution #107

paneq opened this issue Sep 11, 2017 · 2 comments

Comments

@paneq
Copy link
Member

@paneq paneq commented Sep 11, 2017

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.

@paneq
Copy link
Member Author

@paneq paneq commented Sep 11, 2017

BTW

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

This part :

published_events = loaded_events[tried_version+1..version]

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.

But that's just a performance optimization.

@pawelpacana
Copy link
Member

@pawelpacana pawelpacana commented Jun 25, 2019

Duplicate #140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.