Delete is just like Add, but makes an Deleted Delta. If the item does not already exist, it will be ignored. (It may have already been deleted by a Replace (re-list), for example.
(obj interface{})
| 189 | // already exist, it will be ignored. (It may have already been deleted by a |
| 190 | // Replace (re-list), for example. |
| 191 | func (f *DeltaFIFO) Delete(obj interface{}) error { |
| 192 | id, err := f.KeyOf(obj) |
| 193 | if err != nil { |
| 194 | return KeyError{obj, err} |
| 195 | } |
| 196 | f.lock.Lock() |
| 197 | defer f.lock.Unlock() |
| 198 | f.populated = true |
| 199 | if f.knownObjects == nil { |
| 200 | if _, exists := f.items[id]; !exists { |
| 201 | // Presumably, this was deleted when a relist happened. |
| 202 | // Don't provide a second report of the same deletion. |
| 203 | return nil |
| 204 | } |
| 205 | } else { |
| 206 | // We only want to skip the "deletion" action if the object doesn't |
| 207 | // exist in knownObjects and it doesn't have corresponding item in items. |
| 208 | // Note that even if there is a "deletion" action in items, we can ignore it, |
| 209 | // because it will be deduped automatically in "queueActionLocked" |
| 210 | _, exists, err := f.knownObjects.GetByKey(id) |
| 211 | _, itemsExist := f.items[id] |
| 212 | if err == nil && !exists && !itemsExist { |
| 213 | // Presumably, this was deleted when a relist happened. |
| 214 | // Don't provide a second report of the same deletion. |
| 215 | return nil |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return f.queueActionLocked(Deleted, obj) |
| 220 | } |
| 221 | |
| 222 | // AddIfNotPresent inserts an item, and puts it in the queue. If the item is already |
| 223 | // present in the set, it is neither enqueued nor added to the set. |