images: fixed very slow download finish in some use cases

This commit is contained in:
Oleg Agafonov 2024-10-06 12:58:06 +04:00
parent 3c0a62b089
commit a1ca4f5adc

View file

@ -78,7 +78,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
private List<CardInfo> cardsAll; private List<CardInfo> cardsAll;
private List<CardDownloadData> cardsMissing; private List<CardDownloadData> cardsMissing;
private final List<CardDownloadData> cardsDownloadQueue; private List<CardDownloadData> cardsDownloadQueue;
private final List<String> selectedSets = new ArrayList<>(); private final List<String> selectedSets = new ArrayList<>();
private CardImageSource selectedSource; private CardImageSource selectedSource;
@ -975,9 +975,16 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
}); });
// remove all downloaded cards, missing must be remains // remove all downloaded cards, missing must be remains
// TODO: too slow on finished, must be reworked (e.g. run full check instead remove) // workaround for fast remove
this.cardsDownloadQueue.removeAll(downloadedCards); Set<CardDownloadData> finished = new HashSet<>(downloadedCards);
this.cardsMissing.removeAll(downloadedCards); this.cardsDownloadQueue = Collections.synchronizedList(this.cardsDownloadQueue.stream()
.filter(c -> !finished.contains(c))
.collect(Collectors.toList())
);
this.cardsMissing = Collections.synchronizedList(this.cardsMissing.stream()
.filter(c -> !finished.contains(c))
.collect(Collectors.toList())
);
if (this.cardsDownloadQueue.isEmpty()) { if (this.cardsDownloadQueue.isEmpty()) {
// stop download // stop download