aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/session
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-07-17 18:45:33 -0700
committerAnton Tananaev <anton@traccar.org>2022-07-17 18:45:33 -0700
commit6713984001dbdd838d6d8dabcfd252e768f018c4 (patch)
tree1885fa3bf52eea71d39deb07ecc44eb7bd9d7220 /src/main/java/org/traccar/session
parentf12927f06fad1240f368773940719a7f93ae02d5 (diff)
downloadtrackermap-server-6713984001dbdd838d6d8dabcfd252e768f018c4.tar.gz
trackermap-server-6713984001dbdd838d6d8dabcfd252e768f018c4.tar.bz2
trackermap-server-6713984001dbdd838d6d8dabcfd252e768f018c4.zip
Fix group caching
Diffstat (limited to 'src/main/java/org/traccar/session')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java13
1 files changed, 13 insertions, 0 deletions
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<Class<? extends BaseModel>> 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<? extends BaseModel> clazz : CLASSES) {
var objects = storage.getObjects(clazz, new Request(
new Columns.All(), new Condition.Permission(Device.class, deviceId, clazz)));