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

Open
paneq opened this Issue Sep 11, 2017 · 1 comment

Comments

1 participant
@paneq
Member

paneq commented Sep 11, 2017

Idea described here: RailsEventStore/aggregate_root#8 (comment)

This is a separate issue because it's a different idea than just handling concurrency properly.

@paneq

This comment has been minimized.

Show comment
Hide comment
@paneq

paneq Sep 11, 2017

Member

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.

Member

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.

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