Optimize the deletion of statistics data

This commit is contained in:
Xavier Gouchet 2019-10-08 19:49:13 +02:00
parent 5989d6daf6
commit 4289933155
2 changed files with 15 additions and 14 deletions

View File

@ -953,20 +953,7 @@ public class DBWriter {
return dbExec.submit(() -> {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
List<Feed> feeds = DBReader.getFeedList();
for (Feed feed : feeds) {
List<FeedItem> 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();
});
}

View File

@ -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