diff options
author | Anton Tananaev <anton@traccar.org> | 2024-01-15 08:20:34 -0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-01-15 08:20:34 -0800 |
commit | 079eaa6ed49813f4050076ac45849f6e4334e45b (patch) | |
tree | 8c0ba28d8f85f467545b170a3dca5a793b0e84f4 | |
parent | ba1e70e50f6310ec9f331a7e585f004ca4e17298 (diff) | |
download | trackermap-server-079eaa6ed49813f4050076ac45849f6e4334e45b.tar.gz trackermap-server-079eaa6ed49813f4050076ac45849f6e4334e45b.tar.bz2 trackermap-server-079eaa6ed49813f4050076ac45849f6e4334e45b.zip |
Fix duplicate notifications (fix #5245)
-rw-r--r-- | src/main/java/org/traccar/database/NotificationManager.java | 2 | ||||
-rw-r--r-- | src/main/java/org/traccar/session/cache/CacheManager.java | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java index 45263ff3c..65437f0a1 100644 --- a/src/main/java/org/traccar/database/NotificationManager.java +++ b/src/main/java/org/traccar/database/NotificationManager.java @@ -87,7 +87,7 @@ public class NotificationManager { return; } - var notifications = cacheManager.getDeviceNotifications(event.getDeviceId()) + var notifications = cacheManager.getDeviceNotifications(event.getDeviceId()).stream() .filter(notification -> notification.getType().equals(event.getType())) .filter(notification -> { if (event.getType().equals(Event.TYPE_ALARM)) { diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index bb9b4c995..89b25af2f 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -136,14 +136,15 @@ public class CacheManager implements BroadcastInterface { } } - public Stream<Notification> getDeviceNotifications(long deviceId) { + public Set<Notification> getDeviceNotifications(long deviceId) { try { lock.readLock().lock(); var direct = graph.getObjects(Device.class, deviceId, Notification.class, Set.of(Group.class), true) .map(BaseModel::getId) .collect(Collectors.toUnmodifiableSet()); return graph.getObjects(Device.class, deviceId, Notification.class, Set.of(Group.class, User.class), true) - .filter(notification -> notification.getAlways() || direct.contains(notification.getId())); + .filter(notification -> notification.getAlways() || direct.contains(notification.getId())) + .collect(Collectors.toUnmodifiableSet()); } finally { lock.readLock().unlock(); } |