Commit 6bf771b3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

flatpak: do not fetch the size of a resource several times in parallel

There is no need for it. Makes the operation more expensive and it makes
the output too verbose when there's problems.
parent a6dafae4
......@@ -1063,6 +1063,10 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakInstallation *flatpakInstall
return false;
}
if (resource->propertyState(FlatpakResource::DownloadSize) == FlatpakResource::Fetching) {
return true;
}
auto futureWatcher = new QFutureWatcher<FlatpakRunnables::SizeInformation>(this);
connect(futureWatcher, &QFutureWatcher<FlatpakRunnables::SizeInformation>::finished, this, [this, resource, futureWatcher]() {
auto value = futureWatcher->result();
......@@ -1074,6 +1078,9 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakInstallation *flatpakInstall
}
futureWatcher->deleteLater();
});
resource->setPropertyState(FlatpakResource::DownloadSize, FlatpakResource::Fetching);
resource->setPropertyState(FlatpakResource::InstalledSize, FlatpakResource::Fetching);
futureWatcher->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchFlatpakSize, flatpakInstallation, resource));
}
......
......@@ -349,7 +349,7 @@ QString FlatpakResource::sizeDescription()
{
KFormat f;
if (!isInstalled() || canUpgrade()) {
if (propertyState(DownloadSize) == NotKnownYet || propertyState(InstalledSize) == NotKnownYet) {
if (propertyState(DownloadSize) == NotKnownYet || propertyState(InstalledSize) == NotKnownYet || propertyState(DownloadSize) == Fetching || propertyState(InstalledSize) == Fetching) {
return i18n("Retrieving size information");
} else if (propertyState(DownloadSize) == UnknownOrFailed || propertyState(InstalledSize) == UnknownOrFailed) {
return i18n("Unknown size");
......@@ -357,7 +357,7 @@ QString FlatpakResource::sizeDescription()
return i18nc("@info app size", "%1 to download, %2 on disk", f.formatByteSize(downloadSize()), f.formatByteSize(installedSize()));
}
} else {
if (propertyState(InstalledSize) == NotKnownYet) {
if (propertyState(InstalledSize) == NotKnownYet || propertyState(InstalledSize) == Fetching) {
return i18n("Retrieving size information");
} else if (propertyState(InstalledSize) == UnknownOrFailed) {
return i18n("Unknown size");
......
......@@ -38,6 +38,7 @@ public:
NotKnownYet = 0,
AlreadyKnown,
UnknownOrFailed,
Fetching,
};
Q_ENUM(PropertyState)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment