Avoid elements being removed multiple times
as this leads to multiple deletion events in the monitoring.
This commit is contained in:

committed by
Sebastian Serth

parent
d10b31a1fb
commit
6e52b8660d
@ -95,8 +95,11 @@ func (s *localStorage[T]) Get(id string) (o T, ok bool) {
|
|||||||
func (s *localStorage[T]) Delete(id string) {
|
func (s *localStorage[T]) Delete(id string) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
s.sendMonitoringData(id, s.objects[id], true, s.unsafeLength()-1)
|
o, ok := s.objects[id]
|
||||||
delete(s.objects, id)
|
if ok {
|
||||||
|
delete(s.objects, id)
|
||||||
|
s.sendMonitoringData(id, o, true, s.unsafeLength())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *localStorage[T]) Pop(id string) (T, bool) {
|
func (s *localStorage[T]) Pop(id string) (T, bool) {
|
||||||
@ -118,8 +121,8 @@ func (s *localStorage[T]) Sample() (o T, ok bool) {
|
|||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
for key, object := range s.objects {
|
for key, object := range s.objects {
|
||||||
s.sendMonitoringData(key, object, true, s.unsafeLength()-1)
|
|
||||||
delete(s.objects, key)
|
delete(s.objects, key)
|
||||||
|
s.sendMonitoringData(key, object, true, s.unsafeLength())
|
||||||
return object, true
|
return object, true
|
||||||
}
|
}
|
||||||
return o, false
|
return o, false
|
||||||
|
Reference in New Issue
Block a user