From d24edbc439a96b38442be1fbbfaccf65f0dd1923 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 22 Jun 2022 08:58:34 -0700 Subject: Fix accumulator update --- src/main/java/org/traccar/MainEventHandler.java | 2 -- src/main/java/org/traccar/api/resource/DeviceResource.java | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/MainEventHandler.java b/src/main/java/org/traccar/MainEventHandler.java index 965421d2f..06791c540 100644 --- a/src/main/java/org/traccar/MainEventHandler.java +++ b/src/main/java/org/traccar/MainEventHandler.java @@ -89,8 +89,6 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { new Condition.Equals("id", "id"))); cacheManager.updatePosition(position); - cacheManager.getObject(Device.class, position.getDeviceId()).setPositionId(position.getId()); - connectionManager.updatePosition(position); } } catch (StorageException error) { diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java index 74e133f44..ff682d1d1 100644 --- a/src/main/java/org/traccar/api/resource/DeviceResource.java +++ b/src/main/java/org/traccar/api/resource/DeviceResource.java @@ -21,6 +21,7 @@ import org.traccar.model.Device; import org.traccar.model.DeviceAccumulators; import org.traccar.model.Position; import org.traccar.model.User; +import org.traccar.session.ConnectionManager; import org.traccar.session.cache.CacheManager; import org.traccar.storage.StorageException; import org.traccar.storage.query.Columns; @@ -48,6 +49,9 @@ public class DeviceResource extends BaseObjectResource { @Inject private CacheManager cacheManager; + @Inject + private ConnectionManager connectionManager; + public DeviceResource() { super(Device.class); } @@ -125,7 +129,13 @@ public class DeviceResource extends BaseObjectResource { new Columns.Include("positionId"), new Condition.Equals("id", "id"))); - cacheManager.updatePosition(position); + try { + cacheManager.addDevice(position.getDeviceId()); + cacheManager.updatePosition(position); + connectionManager.updatePosition(position); + } finally { + cacheManager.removeDevice(position.getDeviceId()); + } } else { throw new IllegalArgumentException(); } -- cgit v1.2.3