aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorsoshial <soshial@gmail.com>2021-09-18 21:15:24 +0200
committersoshial <soshial@gmail.com>2021-09-18 21:15:24 +0200
commitc345945c36b4c93f2f436cf61f89495577d072ea (patch)
tree4c6e70c7c6f49fa8ee88d3cc6c0e3f96e3cdc643 /src/main
parenta6ccfd679686cfb62f8390334229ba7fdf92eb42 (diff)
downloadtraccar-server-c345945c36b4c93f2f436cf61f89495577d072ea.tar.gz
traccar-server-c345945c36b4c93f2f436cf61f89495577d072ea.tar.bz2
traccar-server-c345945c36b4c93f2f436cf61f89495577d072ea.zip
improve SQL query
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/database/DataManager.java9
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java2
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<Position> 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;