BA-43: Checkout party by revision greedily (#172)

This commit is contained in:
Andrew Mayorov 2018-01-22 17:46:49 +03:00 committed by GitHub
parent 442c626dc2
commit 46c7638166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -553,13 +553,18 @@ checkout_history_by_timestamp([], _, St) ->
checkout_history_by_revision([{_, _, Ev} | Rest], Revision, St) ->
St1 = merge_event(Ev, St),
case get_st_party(St1) of
#domain_Party{revision = Revision} ->
{ok, St1};
#domain_Party{revision = Revision1} when Revision1 > Revision ->
{ok, St};
_ ->
checkout_history_by_revision(Rest, Revision, St1)
end;
checkout_history_by_revision([], _, _) ->
{error, revision_not_found}.
checkout_history_by_revision([], Revision, St) ->
case get_st_party(St) of
#domain_Party{revision = Revision} ->
{ok, St};
_ ->
{error, revision_not_found}
end.
merge_event(?party_ev(PartyChanges), St) when is_list(PartyChanges) ->
lists:foldl(fun merge_party_change/2, St, PartyChanges).