in internal/filter/types/watchlist/watchlist.go [137:162]
func (c *Filter) setMapItem(newItem items.Object, event watch.Event) (cached, isSnapshot, isDeleted bool) {
if event.Type == watch.Deleted {
delete(c.m, newItem.GetUID())
return false, false, true
}
oldItem, ok := c.m[newItem.GetUID()]
if !ok {
c.m[newItem.GetUID()] = items.New(newItem)
return true, false, false
}
// If the new item is older than the cached item, we don't need to update the cache.
switch oldItem.IsState(newItem) {
// This happens when we snapshot objects, we don't need to set the item in the map.
case items.Equal:
return false, true, false
// This happens when the new item is older than the cached item.
case items.Newer:
return false, false, false
}
// We need to update the item in the map.
c.m[newItem.GetUID()] = items.New(newItem)
return true, false, false
}