( ctx context.Context, names []string, ids *ttnpb.EntityIdentifiers, start string, tail int, )
| 174 | } |
| 175 | |
| 176 | func (ps *PubSubStore) tailStream( |
| 177 | ctx context.Context, names []string, ids *ttnpb.EntityIdentifiers, start string, tail int, |
| 178 | ) (eventPBs []*ttnpb.Event, nextStart string, err error) { |
| 179 | matchNames := xMessageHasEventName(names...) |
| 180 | if tail > 0 { |
| 181 | msgs, err := ps.client.XRevRangeN(ctx, ps.eventStream(ctx, ids), "+", start, int64(tail)).Result() |
| 182 | if err != nil { |
| 183 | return nil, "", ttnredis.ConvertError(err) |
| 184 | } |
| 185 | if len(msgs) == 0 { |
| 186 | return nil, start, nil |
| 187 | } |
| 188 | eventPBs = eventsFromXMessages(msgs, matchNames) |
| 189 | reverseEvents(eventPBs) |
| 190 | nextStart = msgs[0].ID |
| 191 | } else { |
| 192 | msgs, err := ps.client.XRange(ctx, ps.eventStream(ctx, ids), start, "+").Result() |
| 193 | if err != nil { |
| 194 | return nil, "", ttnredis.ConvertError(err) |
| 195 | } |
| 196 | if len(msgs) == 0 { |
| 197 | return nil, start, nil |
| 198 | } |
| 199 | eventPBs = eventsFromXMessages(msgs, matchNames) |
| 200 | nextStart = msgs[len(msgs)-1].ID |
| 201 | } |
| 202 | if err = ps.loadEventData(ctx, ps.client, eventPBs...); err != nil { |
| 203 | return nil, "", err |
| 204 | } |
| 205 | return eventPBs, nextStart, nil |
| 206 | } |
| 207 | |
| 208 | // FetchHistory fetches the tail (optional) of historical events matching the given |
| 209 | // names (optional) and identifiers (mandatory) after the given time (optional). |
no test coverage detected