mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-13 05:20:00 -08:00
fixup! [PictureLoader] Keep the download log from going quadratic
Make the URL index a QMultiHash and say why: a deferred retry re-queues the same URL while its first log entry is still pending, so one URL can back several live entries.
This commit is contained in:
parent
b4e3116147
commit
a783ab33b6
2 changed files with 9 additions and 15 deletions
|
|
@ -63,21 +63,21 @@ void CardPictureLoaderStatusBar::addQueuedImageLoad(const QUrl &url, const Exact
|
|||
auto *entry = new CardPictureLoaderRequestStatusDisplayWidget(loadLog, url, card, setName);
|
||||
loadLog->addSettingsWidget(entry);
|
||||
logEntries.append(entry);
|
||||
entriesByUrl[entry->getUrl()].append(entry);
|
||||
entriesByUrl.insert(entry->getUrl(), entry);
|
||||
progressBar->setMaximum(progressBar->maximum() + 1);
|
||||
}
|
||||
|
||||
void CardPictureLoaderStatusBar::addSuccessfulImageLoad(const QUrl &url)
|
||||
{
|
||||
const auto entries = entriesByUrl.constFind(url.toString());
|
||||
if (entries == entriesByUrl.constEnd()) {
|
||||
const QList<CardPictureLoaderRequestStatusDisplayWidget *> entries = entriesByUrl.values(url.toString());
|
||||
if (entries.isEmpty()) {
|
||||
// The entry may already have been dropped from the log; the download
|
||||
// itself still succeeded, there is just nothing left to mark.
|
||||
return;
|
||||
}
|
||||
|
||||
int finishedEntries = 0;
|
||||
for (CardPictureLoaderRequestStatusDisplayWidget *statusDisplayWidget : entries.value()) {
|
||||
for (CardPictureLoaderRequestStatusDisplayWidget *statusDisplayWidget : entries) {
|
||||
if (statusDisplayWidget->getFinished()) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -116,16 +116,8 @@ void CardPictureLoaderStatusBar::removeLogEntry(CardPictureLoaderRequestStatusDi
|
|||
return;
|
||||
}
|
||||
|
||||
const QString entryUrl = entry->getUrl();
|
||||
logEntries.removeOne(entry);
|
||||
|
||||
auto entries = entriesByUrl.find(entryUrl);
|
||||
if (entries != entriesByUrl.end()) {
|
||||
entries.value().removeOne(entry);
|
||||
if (entries.value().isEmpty()) {
|
||||
entriesByUrl.erase(entries);
|
||||
}
|
||||
}
|
||||
entriesByUrl.remove(entry->getUrl(), entry);
|
||||
|
||||
// The progress bar's maximum counts the entries currently in the log and
|
||||
// its value the finished ones, so dropping an entry moves both counters back.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef PICTURE_LOADER_STATUS_BAR_H
|
||||
#define PICTURE_LOADER_STATUS_BAR_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QMultiHash>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <qtmetamacros.h>
|
||||
|
|
@ -85,7 +85,9 @@ private:
|
|||
SettingsButtonWidget *loadLog; ///< Popup log showing individual request statuses
|
||||
QTimer *cleaner; ///< Timer for periodically cleaning old log entries
|
||||
QList<CardPictureLoaderRequestStatusDisplayWidget *> logEntries; ///< Logged requests, oldest first
|
||||
QHash<QString, QList<CardPictureLoaderRequestStatusDisplayWidget *>>
|
||||
// A URL can back several live entries: a request parked for a deferred retry is re-queued while
|
||||
// its first entry is still pending, so a completion must finish every entry for that URL.
|
||||
QMultiHash<QString, CardPictureLoaderRequestStatusDisplayWidget *>
|
||||
entriesByUrl; ///< Log entries indexed by their URL for O(1) completion lookup
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue