Only load the download log entries we actually need (#7974)

This commit is contained in:
Hans-Peter Lehmann 2025-09-07 21:39:26 +02:00 committed by GitHub
parent 6f164648cd
commit e8a18d4887
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 30 deletions

View File

@ -589,8 +589,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
private void showErrorDetails() {
Maybe.fromCallable(
() -> {
List<DownloadResult> feedDownloadLog = DBReader.getFeedDownloadLog(feedID);
if (feedDownloadLog.size() == 0 || feedDownloadLog.get(0).isSuccessful()) {
List<DownloadResult> feedDownloadLog = DBReader.getFeedDownloadLog(feedID, 1);
if (feedDownloadLog.isEmpty() || feedDownloadLog.get(0).isSuccessful()) {
return null;
}
return feedDownloadLog.get(0);

View File

@ -244,7 +244,7 @@ public class FeedUpdateWorker extends Worker {
return savedFeed; // No download logs for new subscriptions
}
// 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()) {
DBWriter.addDownloadStatus(parserTask.getDownloadStatus());
}

View File

@ -18,7 +18,6 @@ import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
@ -68,7 +67,8 @@ public class LocalFeedUpdater {
}
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);
}
return updatedFeed;
@ -269,27 +269,6 @@ public class LocalFeedUpdater {
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
public interface UpdaterProgressListener {
void onLocalFileScanned(int scanned, int totalFiles);

View File

@ -321,13 +321,13 @@ public final class DBReader {
* @return A list with DownloadStatus objects that represent the feed's download log,
* 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 + "]");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
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());
while (cursor.moveToNext()) {
downloadLog.add(cursor.getDownloadResult());

View File

@ -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 +
" 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);
}