From 43942f459f456b05c62ea7549123e28fd7560d56 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 2 Jun 2022 17:38:12 -0700 Subject: Inverse user notification cache --- .../java/org/traccar/session/cache/CacheManager.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index d019b072b..f6f04cc36 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -59,7 +59,7 @@ public class CacheManager { private final Map deviceCache = new HashMap<>(); private final Map, List>> deviceLinks = new HashMap<>(); - private final Map> userNotifications = new HashMap<>(); + private final Map> notificationUsers = new HashMap<>(); @Inject public CacheManager(Storage storage) throws StorageException { @@ -87,10 +87,10 @@ public class CacheManager { } } - public List getUserNotifications(long userId) { + public List getNotificationUsers(long notificationId) { try { lock.readLock().lock(); - return userNotifications.get(userId); + return notificationUsers.get(notificationId); } finally { lock.readLock().unlock(); } @@ -130,13 +130,13 @@ public class CacheManager { } private void invalidateUsers() throws StorageException { - Map notifications = new HashMap<>(); - storage.getObjects(Notification.class, new Request(new Columns.All())) - .forEach(notification -> notifications.put(notification.getId(), notification)); + Map users = new HashMap<>(); + storage.getObjects(User.class, new Request(new Columns.All())) + .forEach(user -> users.put(user.getId(), user)); storage.getPermissions(User.class, Notification.class).forEach(permission -> { - long userId = permission.getOwnerId(); - var notification = notifications.get(permission.getPropertyId()); - userNotifications.computeIfAbsent(userId, k -> new LinkedList<>()).add(notification); + long notificationId = permission.getPropertyId();; + var user = users.get(permission.getOwnerId()); + notificationUsers.computeIfAbsent(notificationId, k -> new LinkedList<>()).add(user); }); } -- cgit v1.2.3