mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
Only load the download log entries we actually need (#7974)
This commit is contained in:
committed by
GitHub
parent
6f164648cd
commit
e8a18d4887
@ -589,8 +589,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
|
|||||||
private void showErrorDetails() {
|
private void showErrorDetails() {
|
||||||
Maybe.fromCallable(
|
Maybe.fromCallable(
|
||||||
() -> {
|
() -> {
|
||||||
List<DownloadResult> feedDownloadLog = DBReader.getFeedDownloadLog(feedID);
|
List<DownloadResult> feedDownloadLog = DBReader.getFeedDownloadLog(feedID, 1);
|
||||||
if (feedDownloadLog.size() == 0 || feedDownloadLog.get(0).isSuccessful()) {
|
if (feedDownloadLog.isEmpty() || feedDownloadLog.get(0).isSuccessful()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return feedDownloadLog.get(0);
|
return feedDownloadLog.get(0);
|
||||||
|
|||||||
@ -244,7 +244,7 @@ public class FeedUpdateWorker extends Worker {
|
|||||||
return savedFeed; // No download logs for new subscriptions
|
return savedFeed; // No download logs for new subscriptions
|
||||||
}
|
}
|
||||||
// we create a 'successful' download log if the feed's last refresh failed
|
// we create a 'successful' download log if the feed's last refresh failed
|
||||||
List<DownloadResult> log = DBReader.getFeedDownloadLog(request.getFeedfileId());
|
List<DownloadResult> log = DBReader.getFeedDownloadLog(request.getFeedfileId(), 1);
|
||||||
if (!log.isEmpty() && !log.get(0).isSuccessful()) {
|
if (!log.isEmpty() && !log.get(0).isSuccessful()) {
|
||||||
DBWriter.addDownloadStatus(parserTask.getDownloadStatus());
|
DBWriter.addDownloadStatus(parserTask.getDownloadStatus());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import java.io.InputStream;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -68,7 +67,8 @@ public class LocalFeedUpdater {
|
|||||||
}
|
}
|
||||||
Feed updatedFeed = tryUpdateFeed(feed, context, documentFolder.getUri(), updaterProgressListener);
|
Feed updatedFeed = tryUpdateFeed(feed, context, documentFolder.getUri(), updaterProgressListener);
|
||||||
|
|
||||||
if (mustReportDownloadSuccessful(feed)) {
|
List<DownloadResult> downloadResults = DBReader.getFeedDownloadLog(feed.getId(), 1);
|
||||||
|
if (downloadResults.isEmpty() || !downloadResults.get(0).isSuccessful()) {
|
||||||
reportSuccess(feed);
|
reportSuccess(feed);
|
||||||
}
|
}
|
||||||
return updatedFeed;
|
return updatedFeed;
|
||||||
@ -269,27 +269,6 @@ public class LocalFeedUpdater {
|
|||||||
DBWriter.setFeedLastUpdateFailed(feed.getId(), false);
|
DBWriter.setFeedLastUpdateFailed(feed.getId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Answers if reporting success is needed for the given feed.
|
|
||||||
*/
|
|
||||||
private static boolean mustReportDownloadSuccessful(Feed feed) {
|
|
||||||
List<DownloadResult> downloadResults = DBReader.getFeedDownloadLog(feed.getId());
|
|
||||||
|
|
||||||
if (downloadResults.isEmpty()) {
|
|
||||||
// report success if never reported before
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(downloadResults, (downloadStatus1, downloadStatus2) ->
|
|
||||||
downloadStatus1.getCompletionDate().compareTo(downloadStatus2.getCompletionDate()));
|
|
||||||
|
|
||||||
DownloadResult lastDownloadResult = downloadResults.get(downloadResults.size() - 1);
|
|
||||||
|
|
||||||
// report success if the last update was not successful
|
|
||||||
// (avoid logging success again if the last update was ok)
|
|
||||||
return !lastDownloadResult.isSuccessful();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface UpdaterProgressListener {
|
public interface UpdaterProgressListener {
|
||||||
void onLocalFileScanned(int scanned, int totalFiles);
|
void onLocalFileScanned(int scanned, int totalFiles);
|
||||||
|
|||||||
@ -321,13 +321,13 @@ public final class DBReader {
|
|||||||
* @return A list with DownloadStatus objects that represent the feed's download log,
|
* @return A list with DownloadStatus objects that represent the feed's download log,
|
||||||
* newest events first.
|
* newest events first.
|
||||||
*/
|
*/
|
||||||
public static List<DownloadResult> getFeedDownloadLog(long feedId) {
|
public static List<DownloadResult> getFeedDownloadLog(long feedId, long limit) {
|
||||||
Log.d(TAG, "getFeedDownloadLog() called with: " + "feed = [" + feedId + "]");
|
Log.d(TAG, "getFeedDownloadLog() called with: " + "feed = [" + feedId + "]");
|
||||||
|
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
try (DownloadResultCursor cursor = new DownloadResultCursor(
|
try (DownloadResultCursor cursor = new DownloadResultCursor(
|
||||||
adapter.getDownloadLog(Feed.FEEDFILETYPE_FEED, feedId))) {
|
adapter.getDownloadLog(Feed.FEEDFILETYPE_FEED, feedId, limit))) {
|
||||||
List<DownloadResult> downloadLog = new ArrayList<>(cursor.getCount());
|
List<DownloadResult> downloadLog = new ArrayList<>(cursor.getCount());
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
downloadLog.add(cursor.getDownloadResult());
|
downloadLog.add(cursor.getDownloadResult());
|
||||||
|
|||||||
@ -1015,10 +1015,10 @@ public class PodDBAdapter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Cursor getDownloadLog(final int feedFileType, final long feedFileId) {
|
public final Cursor getDownloadLog(final int feedFileType, final long feedFileId, final long limit) {
|
||||||
final String query = "SELECT * FROM " + TABLE_NAME_DOWNLOAD_LOG +
|
final String query = "SELECT * FROM " + TABLE_NAME_DOWNLOAD_LOG +
|
||||||
" WHERE " + KEY_FEEDFILE + "=" + feedFileId + " AND " + KEY_FEEDFILETYPE + "=" + feedFileType
|
" WHERE " + KEY_FEEDFILE + "=" + feedFileId + " AND " + KEY_FEEDFILETYPE + "=" + feedFileType
|
||||||
+ " ORDER BY " + KEY_COMPLETION_DATE + " DESC";
|
+ " ORDER BY " + KEY_COMPLETION_DATE + " DESC LIMIT " + limit;
|
||||||
return db.rawQuery(query, null);
|
return db.rawQuery(query, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user