diff --git a/TODO.md b/TODO.md index 4fce7f5..3ec4994 100644 --- a/TODO.md +++ b/TODO.md @@ -14,3 +14,4 @@ * Encode machine events and responses with a schema-aware protocol * Thrift / compact protocol? * Fix potential race when a `Repository` request getting processed earlier than the start machine request being issued. +* Don't go to the cache for getting `Head` reference diff --git a/src/dmt_api_mg.erl b/src/dmt_api_mg.erl index 730b202..51a4076 100644 --- a/src/dmt_api_mg.erl +++ b/src/dmt_api_mg.erl @@ -50,10 +50,11 @@ get_prev_commit(N) -> get_history(Context) -> get_history(undefined, undefined, Context). +%% TODO: change this interface to accept dmt:version only -spec get_history(dmt:version() | undefined, pos_integer() | undefined, context()) -> {dmt:history() | {error, version_not_found}, context()}. get_history(After, Limit, Context) -> - Range = #'HistoryRange'{'after' = After, 'limit' = Limit}, + Range = #'HistoryRange'{'after' = prepare_event_id(After), 'limit' = Limit}, try dmt_api_context:map(call('GetHistory', [?REF, Range], Context), fun read_history/1) catch {{exception, #'EventNotFound'{}}, Context1} -> {{error, version_not_found}, Context1} @@ -92,3 +93,8 @@ read_history([], History) -> History; read_history([#'Event'{id = Id, event_payload = BinaryPayload} | Rest], History) -> read_history(Rest, History#{Id => binary_to_term(BinaryPayload)}). + +prepare_event_id(ID) when is_integer(ID) andalso ID > 0 -> + ID; +prepare_event_id(_) -> + undefined.