From d42f935e4119fb87002b8b275c4237290ef7f12b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Jul 2022 18:21:31 -0700 Subject: Fix duplicate notifications --- src/main/java/org/traccar/session/cache/CacheManager.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/traccar/session/cache') diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index 0865b2647..07f27d776 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -42,6 +42,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -65,7 +66,7 @@ public class CacheManager implements BroadcastInterface { private final Map deviceCache = new HashMap<>(); private final Map deviceReferences = new HashMap<>(); - private final Map, List>> deviceLinks = new HashMap<>(); + private final Map, Set>> deviceLinks = new HashMap<>(); private final Map devicePositions = new HashMap<>(); private Server server; @@ -271,7 +272,7 @@ public class CacheManager implements BroadcastInterface { } private void unsafeAddDevice(long deviceId) throws StorageException { - Map, List> links = new HashMap<>(); + Map, Set> links = new HashMap<>(); Device device = storage.getObject(Device.class, new Request( new Columns.All(), new Condition.Equals("id", "id", deviceId))); @@ -283,7 +284,7 @@ public class CacheManager implements BroadcastInterface { while (groupDepth < GROUP_DEPTH_LIMIT && groupId > 0) { Group group = storage.getObject(Group.class, new Request( new Columns.All(), new Condition.Equals("id", "id", groupId))); - links.computeIfAbsent(Group.class, k -> new LinkedList<>()).add(group.getId()); + links.computeIfAbsent(Group.class, k -> new LinkedHashSet<>()).add(group.getId()); addObject(deviceId, group); groupId = group.getGroupId(); groupDepth += 1; @@ -292,13 +293,13 @@ public class CacheManager implements BroadcastInterface { for (Class clazz : CLASSES) { var objects = storage.getObjects(clazz, new Request( new Columns.All(), new Condition.Permission(Device.class, deviceId, clazz))); - links.put(clazz, objects.stream().map(BaseModel::getId).collect(Collectors.toList())); + links.put(clazz, objects.stream().map(BaseModel::getId).collect(Collectors.toSet())); objects.forEach(object -> addObject(deviceId, object)); } var users = storage.getObjects(User.class, new Request( new Columns.All(), new Condition.Permission(User.class, Device.class, deviceId))); - links.put(User.class, users.stream().map(BaseModel::getId).collect(Collectors.toList())); + links.put(User.class, users.stream().map(BaseModel::getId).collect(Collectors.toSet())); for (var user : users) { addObject(deviceId, user); var notifications = storage.getObjects(Notification.class, new Request( @@ -306,7 +307,7 @@ public class CacheManager implements BroadcastInterface { notifications.stream() .filter(Notification::getAlways) .forEach(object -> { - links.computeIfAbsent(Notification.class, k -> new LinkedList<>()).add(object.getId()); + links.computeIfAbsent(Notification.class, k -> new LinkedHashSet<>()).add(object.getId()); addObject(deviceId, object); }); } -- cgit v1.2.3