58 lines
2.4 KiB
Diff
58 lines
2.4 KiB
Diff
--- a/src/org/droidtv/channels/epg/bcepg/EpgProvider.java
|
|
+++ b/src/org/droidtv/channels/epg/bcepg/EpgProvider.java
|
|
@@
|
|
- long staleTime = System.currentTimeMillis() - 1800L;
|
|
- if (epgInfo != null && epgInfo.isFreeViewAvailable()) {
|
|
- staleTime -= 604800L;
|
|
- }
|
|
- Log.d(TAG, "Deleting stale data for time " + staleTime);
|
|
+ final long nowMillis = System.currentTimeMillis();
|
|
+ final long cutoffSeconds = TimeUnit.MILLISECONDS.toSeconds(nowMillis)
|
|
+ - TimeUnit.DAYS.toSeconds(7);
|
|
+ maintenanceExecutor.execute(() -> {
|
|
+ EpgCleanupResult r = mDbHelper.deleteOldScheduleInBatches(
|
|
+ cutoffSeconds, 2000);
|
|
+ Log.i(TAG, "EPG cleanup unit=seconds cutoff=" + cutoffSeconds
|
|
+ + " deleted=" + r.deleted + " batches=" + r.batches
|
|
+ + " durationMs=" + r.durationMs);
|
|
+ });
|
|
|
|
--- a/src/org/droidtv/channels/epg/bcepg/EpgDatabaseHelper.java
|
|
+++ b/src/org/droidtv/channels/epg/bcepg/EpgDatabaseHelper.java
|
|
@@
|
|
+ EpgCleanupResult deleteOldScheduleInBatches(long cutoffSeconds, int batchSize) {
|
|
+ if (batchSize < 1 || batchSize > 2000
|
|
+ || cutoffSeconds < 1_000_000_000L
|
|
+ || cutoffSeconds > 4_102_444_800L) {
|
|
+ throw new IllegalArgumentException("invalid cleanup boundary");
|
|
+ }
|
|
+ SQLiteDatabase db = getWritableDatabase();
|
|
+ int total = 0, batches = 0;
|
|
+ long started = SystemClock.elapsedRealtime();
|
|
+ for (;;) {
|
|
+ int changed;
|
|
+ db.beginTransactionNonExclusive();
|
|
+ try {
|
|
+ db.execSQL("DELETE FROM scheduletable WHERE _id IN ("
|
|
+ + "SELECT _id FROM scheduletable WHERE endtime < ? "
|
|
+ + "ORDER BY endtime, _id LIMIT ?)",
|
|
+ new Object[]{cutoffSeconds, batchSize});
|
|
+ changed = (int) DatabaseUtils.longForQuery(
|
|
+ db, "SELECT changes()", null);
|
|
+ db.setTransactionSuccessful();
|
|
+ } finally {
|
|
+ db.endTransaction();
|
|
+ }
|
|
+ total += changed;
|
|
+ batches++;
|
|
+ if (changed < batchSize || Thread.currentThread().isInterrupted()) break;
|
|
+ SystemClock.sleep(100);
|
|
+ }
|
|
+ return new EpgCleanupResult(total, batches,
|
|
+ SystemClock.elapsedRealtime() - started);
|
|
+ }
|
|
|
|
# Reconstructed source-level specification. Do not apply blindly to a Philips
|
|
# source tree. Acquisition locking and the existing provider monitor must be
|
|
# integrated and tested in the vendor implementation.
|