Fix end position in case of backward ordering

This commit is contained in:
Brendan Abolivier 2018-12-11 11:33:45 +00:00
parent 955dd2c96d
commit b028a31f7f
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -220,7 +220,18 @@ func (r *messagesReq) retrieveEvents() (
types.PaginationTokenTypeTopology, streamEvents[len(streamEvents)-1].StreamPosition,
)
if end.Position == types.StreamPosition(0) {
if r.backwardOrdering {
// A stream/topological position is a cursor located between two events.
// While they are identified in the code by the event on their right (if
// we consider a left to right chronological order), tokens need to refer
// to them by the event on their left, therefore we need to decrement the
// end position we send in the response if we're going backward.
end.Position--
}
// The lowest token value is 1, therefore we need to manually set it to that
// value if we're below it.
if end.Position < types.StreamPosition(1) {
end.Position = types.StreamPosition(1)
}