From 6713984001dbdd838d6d8dabcfd252e768f018c4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 17 Jul 2022 18:45:33 -0700 Subject: Fix group caching --- src/main/java/org/traccar/session/cache/CacheManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index 58eb95327..0865b2647 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -23,6 +23,7 @@ import org.traccar.model.BaseModel; import org.traccar.model.Device; import org.traccar.model.Driver; import org.traccar.model.Geofence; +import org.traccar.model.Group; import org.traccar.model.GroupedModel; import org.traccar.model.Maintenance; import org.traccar.model.Notification; @@ -52,6 +53,7 @@ import java.util.stream.Collectors; @Singleton public class CacheManager implements BroadcastInterface { + private static final int GROUP_DEPTH_LIMIT = 3; private static final Collection> CLASSES = Arrays.asList( Attribute.class, Driver.class, Geofence.class, Maintenance.class, Notification.class); @@ -276,6 +278,17 @@ public class CacheManager implements BroadcastInterface { if (device != null) { addObject(deviceId, device); + int groupDepth = 0; + long groupId = device.getGroupId(); + 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()); + addObject(deviceId, group); + groupId = group.getGroupId(); + groupDepth += 1; + } + for (Class clazz : CLASSES) { var objects = storage.getObjects(clazz, new Request( new Columns.All(), new Condition.Permission(Device.class, deviceId, clazz))); -- cgit v1.2.3