Skip to content

Commit

Permalink
Clear event history (fix #3160)
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed May 11, 2017
1 parent b5a311c commit dd32e2d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions setup/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices)
</entry>

<entry key='database.deleteEvents'>
DELETE FROM events WHERE serverTime &lt; :serverTime
</entry>

<entry key='database.selectAttributeAliases'>
SELECT * FROM attribute_aliases
</entry>
Expand Down
2 changes: 1 addition & 1 deletion src/org/traccar/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void main(String[] args) throws Exception {
@Override
public void run() {
try {
Context.getDataManager().clearPositionsHistory();
Context.getDataManager().clearHistory();
} catch (SQLException error) {
Log.warning(error);
}
Expand Down
7 changes: 5 additions & 2 deletions src/org/traccar/database/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,15 @@ public Collection<Position> getLatestPositions() throws SQLException {
.executeQuery(Position.class);
}

public void clearPositionsHistory() throws SQLException {
long historyDays = config.getInteger("database.positionsHistoryDays");
public void clearHistory() throws SQLException {
long historyDays = config.getInteger("database.historyDays");
if (historyDays != 0) {
QueryBuilder.create(dataSource, getQuery("database.deletePositions"))
.setDate("serverTime", new Date(System.currentTimeMillis() - historyDays * 24 * 3600 * 1000))
.executeUpdate();
QueryBuilder.create(dataSource, getQuery("database.deleteEvents"))
.setDate("serverTime", new Date(System.currentTimeMillis() - historyDays * 24 * 3600 * 1000))
.executeUpdate();
}
}

Expand Down

0 comments on commit dd32e2d

Please sign in to comment.