aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java
index bc5fc357f..9d1db7d14 100644
--- a/src/main/java/org/traccar/session/cache/CacheManager.java
+++ b/src/main/java/org/traccar/session/cache/CacheManager.java
@@ -268,38 +268,40 @@ public class CacheManager implements BroadcastInterface {
Device device = storage.getObject(Device.class, new Request(
new Columns.All(), new Condition.Equals("id", "id", deviceId)));
- addObject(deviceId, device);
+ if (device != null) {
+ addObject(deviceId, device);
+
+ for (Class<? extends BaseModel> 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()));
+ objects.forEach(object -> addObject(deviceId, object));
+ }
- for (Class<? extends BaseModel> 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()));
- 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()));
+ for (var user : users) {
+ addObject(deviceId, user);
+ var notifications = storage.getObjects(Notification.class, new Request(
+ new Columns.All(), new Condition.Permission(User.class, user.getId(), Notification.class)));
+ notifications.stream()
+ .filter(Notification::getAlways)
+ .forEach(object -> {
+ links.computeIfAbsent(Notification.class, k -> new LinkedList<>()).add(object.getId());
+ 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()));
- for (var user : users) {
- addObject(deviceId, user);
- var notifications = storage.getObjects(Notification.class, new Request(
- new Columns.All(), new Condition.Permission(User.class, user.getId(), Notification.class)));
- notifications.stream()
- .filter(Notification::getAlways)
- .forEach(object -> {
- links.computeIfAbsent(Notification.class, k -> new LinkedList<>()).add(object.getId());
- addObject(deviceId, object);
- });
- }
+ deviceLinks.put(deviceId, links);
- deviceLinks.put(deviceId, links);
+ if (device.getPositionId() > 0) {
+ devicePositions.put(deviceId, storage.getObject(Position.class, new Request(
+ new Columns.All(), new Condition.Equals("id", "id", device.getPositionId()))));
+ }
- if (device.getPositionId() > 0) {
- devicePositions.put(deviceId, storage.getObject(Position.class, new Request(
- new Columns.All(), new Condition.Equals("id", "id", device.getPositionId()))));
+ invalidateDeviceGeofences(device);
}
-
- invalidateDeviceGeofences(device);
}
private void unsafeRemoveDevice(long deviceId) {