From 4289933155a72f1dd6e89ead54f7add3a6145ef5 Mon Sep 17 00:00:00 2001 From: Xavier Gouchet Date: Tue, 8 Oct 2019 19:49:13 +0200 Subject: [PATCH] Optimize the deletion of statistics data --- .../danoeh/antennapod/core/storage/DBWriter.java | 15 +-------------- .../antennapod/core/storage/PodDBAdapter.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index 2113679b9..e0e15c1ff 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -953,20 +953,7 @@ public class DBWriter { return dbExec.submit(() -> { PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - - List feeds = DBReader.getFeedList(); - for (Feed feed : feeds) { - List items = DBReader.getFeed(feed.getId()).getItems(); - for (FeedItem item : items) { - FeedMedia media = item.getMedia(); - if (media == null) { - continue; - } - - media.setPlayedDuration(0); - adapter.setFeedMediaPlaybackInformation(media); - } - } + adapter.resetAllMediaPlayedDuration(); adapter.close(); }); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 5feedcebf..66f6d223d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -476,6 +476,20 @@ public class PodDBAdapter { } } + public void resetAllMediaPlayedDuration() { + try { + db.beginTransactionNonExclusive(); + ContentValues values = new ContentValues(); + values.put(KEY_PLAYED_DURATION, 0); + db.update(TABLE_NAME_FEED_MEDIA, values, null, new String[0]); + db.setTransactionSuccessful(); + } catch (SQLException e) { + Log.e(TAG, Log.getStackTraceString(e)); + } finally { + db.endTransaction(); + } + } + /** * Insert all FeedItems of a feed and the feed object itself in a single * transaction