58 lines
2.6 KiB
Diff
58 lines
2.6 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);
|
|
+ // Contract: TV clock is milliseconds; the physical EPG columns are epoch seconds.
|
|
+ final long nowMillis = System.currentTimeMillis();
|
|
+ final long cutoffSeconds = TimeUnit.MILLISECONDS.toSeconds(nowMillis)
|
|
+ - TimeUnit.DAYS.toSeconds(7);
|
|
+ final EpgCleanupResult result = mDbHelper.deleteOldScheduleInBatches(
|
|
+ cutoffSeconds, 2000);
|
|
+ Log.i(TAG, "EPG cleanup unit=seconds cutoff=" + cutoffSeconds
|
|
+ + " deleted=" + result.deleted + " batches=" + result.batches
|
|
+ + " durationMs=" + result.durationMs);
|
|
+ mEpgProviderHandler.removeCallbacks(mDeleteStaleDataRunnable);
|
|
+ mEpgProviderHandler.postDelayed(mDeleteStaleDataRunnable,
|
|
+ TimeUnit.DAYS.toMillis(1));
|
|
|
|
--- 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 (cutoffSeconds < 1_000_000_000L || cutoffSeconds > 4_102_444_800L) {
|
|
+ throw new IllegalArgumentException("cutoff is not plausible epoch seconds");
|
|
+ }
|
|
+ final SQLiteDatabase db = getWritableDatabase();
|
|
+ int total = 0;
|
|
+ int batches = 0;
|
|
+ int n;
|
|
+ final long started = SystemClock.elapsedRealtime();
|
|
+ do {
|
|
+ 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 });
|
|
+ n = (int) DatabaseUtils.longForQuery(db, "SELECT changes()", null);
|
|
+ db.setTransactionSuccessful();
|
|
+ } finally {
|
|
+ db.endTransaction();
|
|
+ }
|
|
+ total += n;
|
|
+ batches++;
|
|
+ if (n == batchSize) SystemClock.sleep(100);
|
|
+ } while (n == batchSize && !Thread.currentThread().isInterrupted());
|
|
+ return new EpgCleanupResult(total, batches,
|
|
+ SystemClock.elapsedRealtime() - started);
|
|
+ }
|
|
|
|
# This is a source-level implementation specification reconstructed from DEX.
|
|
# It is not claimed to apply cleanly to an unavailable Philips source tree.
|
|
# A production integration must also move the database work outside the
|
|
# provider-wide monitor currently held by deleteStaleDataRunnable.run().
|