Use (the last existing timestamp in DB + 1) as the start time of usage

event query to avoid loading the same events repeatedly.

queryEvents API will return the events within [start, end). In the
hourly job, if we query the events from the latest existing time, the
events happening at the latest time will be saved for multiple times
into database. This aims to avoid this issue.

Test: make RunSettingsRoboTests
Bug: 265110147
Fix: 265110147
Change-Id: I408e88b0e15fe22585906261935854cf47707f9c
This commit is contained in:
Kuan Wang
2023-01-11 16:18:55 +08:00
parent 89e5b837b9
commit 6da66f9a5c
2 changed files with 4 additions and 2 deletions

View File

@@ -125,7 +125,9 @@ public final class DatabaseUtils {
Log.d(TAG, String.format(
"getAppUsageStartTimestampOfUser() userId=%d latestTimestamp=%d in %d/ms",
userId, latestTimestamp, (System.currentTimeMillis() - startTime)));
return Math.max(latestTimestamp, earliestTimestamp);
// Use (latestTimestamp + 1) here to avoid loading the events of the latestTimestamp
// repeatedly.
return Math.max(latestTimestamp + 1, earliestTimestamp);
}
/** Returns the current user data in app usage event table. */