From c345945c36b4c93f2f436cf61f89495577d072ea Mon Sep 17 00:00:00 2001 From: soshial Date: Sat, 18 Sep 2021 21:15:24 +0200 Subject: improve SQL query --- src/main/java/org/traccar/database/DataManager.java | 9 ++------- src/main/java/org/traccar/handler/FilterHandler.java | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java index 15c67cb74..75ec70ea7 100644 --- a/src/main/java/org/traccar/database/DataManager.java +++ b/src/main/java/org/traccar/database/DataManager.java @@ -329,15 +329,10 @@ public class DataManager { } public Position getPrecedingPosition(long deviceId, Date date) throws SQLException { - Collection positions = QueryBuilder.create(dataSource, getQuery("database.selectPrecedingPosition")) + return QueryBuilder.create(dataSource, getQuery("database.selectPrecedingPosition")) .setLong("deviceId", deviceId) .setDate("time", date) - .executeQuery(Position.class); - if (positions.isEmpty()) { - return null; - } else { - return positions.iterator().next(); - } + .executeQuerySingle(Position.class); } public void updateLatestPosition(Position position) throws SQLException { diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java index 6331ff773..19d72d8a1 100644 --- a/src/main/java/org/traccar/handler/FilterHandler.java +++ b/src/main/java/org/traccar/handler/FilterHandler.java @@ -74,7 +74,7 @@ public class FilterHandler extends BaseDataHandler { } private boolean filterDuplicate(Position position, Position last) { - if (filterDuplicate && last != null && position.getFixTime().equals(last.getFixTime())) { + if (filterDuplicate && last != null && position.getFixTime().getTime() == last.getFixTime().getTime()) { for (String key : position.getAttributes().keySet()) { if (!last.getAttributes().containsKey(key)) { return false; -- cgit v1.2.3