GetLastInterestedEventTimestamp: return early

on the happy path
This commit is contained in:
David Robertson 2023-05-25 11:28:12 +01:00
parent 4f69909f8b
commit f5d588678d
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD

View File

@ -52,16 +52,17 @@ type RoomConnMetadata struct {
func (r *RoomConnMetadata) GetLastInterestedEventTimestamp(listKey string) uint64 {
ts, ok := r.LastInterestedEventTimestamps[listKey]
if !ok {
// SetRoom is responsible for maintaining LastInterestedEventTimestamps.
// However, if a brand-new list appears and we don't call SetRoom, we need to
// ensure we hand back a sensible timestamp. So: use the (current)
// LastMessageTimestamp as a fallback.
ts = r.LastMessageTimestamp
// Write this value into the map. If we don't and only uninteresting events
// arrive after, the fallback value will have jumped ahead despite nothing of
// interest happening.
r.LastInterestedEventTimestamps[listKey] = ts
if ok {
return ts
}
// SetRoom is responsible for maintaining LastInterestedEventTimestamps.
// However, if a brand-new list appears and we don't call SetRoom, we need to
// ensure we hand back a sensible timestamp. So: use the (current)
// LastMessageTimestamp as a fallback.
ts = r.LastMessageTimestamp
// Write this value into the map. If we don't and only uninteresting events
// arrive after, the fallback value will have jumped ahead despite nothing of
// interest happening.
r.LastInterestedEventTimestamps[listKey] = ts
return ts
}