diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-07 18:04:24 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-07 18:04:24 -0700 |
commit | 104281f161f622df8fca0c65a5b9969ceb03c46f (patch) | |
tree | d9bc756c29a9088a762bb434c443fccbb1eb9e7e /src/main/java/org/traccar/session/cache | |
parent | b745e3804950fefd24b38937c90c4d5c61219321 (diff) | |
download | trackermap-server-104281f161f622df8fca0c65a5b9969ceb03c46f.tar.gz trackermap-server-104281f161f622df8fca0c65a5b9969ceb03c46f.tar.bz2 trackermap-server-104281f161f622df8fca0c65a5b9969ceb03c46f.zip |
Extract user utils from reports
Diffstat (limited to 'src/main/java/org/traccar/session/cache')
-rw-r--r-- | src/main/java/org/traccar/session/cache/CacheManager.java | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index 6ea0f252d..586237655 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.Geofence; import org.traccar.model.Maintenance; import org.traccar.model.Notification; import org.traccar.model.Position; +import org.traccar.model.Server; import org.traccar.model.User; import org.traccar.storage.Storage; import org.traccar.storage.StorageException; @@ -57,12 +58,14 @@ public class CacheManager { private final Map<CacheKey, CacheValue> deviceCache = new HashMap<>(); private final Map<Long, Map<Class<? extends BaseModel>, List<Long>>> deviceLinks = new HashMap<>(); + private Server server; private final Map<Long, Position> devicePositions = new HashMap<>(); private final Map<Long, List<User>> notificationUsers = new HashMap<>(); @Inject public CacheManager(Storage storage) throws StorageException { this.storage = storage; + invalidateServer(); invalidateUsers(); } @@ -96,6 +99,15 @@ public class CacheManager { } } + public Server getServer() { + try { + lock.readLock().lock(); + return server; + } finally { + lock.readLock().unlock(); + } + } + public List<User> getNotificationUsers(long notificationId) { try { lock.readLock().lock(); @@ -154,6 +166,10 @@ public class CacheManager { invalidate(new CacheKey(clazz1, id1), new CacheKey(clazz2, id2)); } + private void invalidateServer() throws StorageException { + server = storage.getObject(Server.class, new Request(new Columns.All())); + } + private void invalidateUsers() throws StorageException { Map<Long, User> users = new HashMap<>(); storage.getObjects(User.class, new Request(new Columns.All())) @@ -220,21 +236,29 @@ public class CacheManager { } private void unsafeInvalidate(CacheKey[] keys) throws StorageException { + boolean invalidateServer = false; boolean invalidateUsers = false; Set<Long> linkedDevices = new HashSet<>(); for (var key : keys) { - if (key.classIs(User.class) || key.classIs(Notification.class)) { - invalidateUsers = true; + if (key.classIs(Server.class)) { + invalidateServer = true; + } else { + if (key.classIs(User.class) || key.classIs(Notification.class)) { + invalidateUsers = true; + } + deviceCache.computeIfPresent(key, (k, value) -> { + linkedDevices.addAll(value.getReferences()); + return value; + }); } - deviceCache.computeIfPresent(key, (k, value) -> { - linkedDevices.addAll(value.getReferences()); - return value; - }); } for (long deviceId : linkedDevices) { unsafeRemoveDevice(deviceId); unsafeAddDevice(deviceId); } + if (invalidateServer) { + invalidateServer(); + } if (invalidateUsers) { invalidateUsers(); } |