Commit 94889545 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Move appstream metadata parsing into a separate async thread

It's rather expensive and freezes the startup of the whole process
parent cd72d6a1
......@@ -590,26 +590,32 @@ void FlatpakBackend::integrateRemote(FlatpakInstallation *flatpakInstallation, F
return;
}
AppStream::Metadata metadata;
metadata.setFormatStyle(AppStream::Metadata::FormatStyleCollection);
AppStream::Metadata::MetadataError error = metadata.parseFile(appDirFileName, AppStream::Metadata::FormatKindXml);
if (error != AppStream::Metadata::MetadataErrorNoError) {
qWarning() << "Failed to parse appstream metadata: " << error;
return;
}
QList<AppStream::Component> components = metadata.components();
foreach (const AppStream::Component& appstreamComponent, components) {
FlatpakResource *resource = new FlatpakResource(appstreamComponent, flatpakInstallation, this);
resource->setIconPath(appstreamIconsPath);
resource->setOrigin(source.name());
addResource(resource);
}
auto fw = new QFutureWatcher<QList<AppStream::Component>>(this);
fw->setFuture(QtConcurrent::run(&m_threadPool, [appDirFileName]() -> QList<AppStream::Component> {
AppStream::Metadata metadata;
metadata.setFormatStyle(AppStream::Metadata::FormatStyleCollection);
AppStream::Metadata::MetadataError error = metadata.parseFile(appDirFileName, AppStream::Metadata::FormatKindXml);
if (error != AppStream::Metadata::MetadataErrorNoError) {
qWarning() << "Failed to parse appstream metadata: " << error;
return {};
}
// Not ideal calling it from here but given that everything is asynchronous then it's a bit complicated
if (!m_refreshAppstreamMetadataJobs) {
finishInitialization();
}
return metadata.components();
}));
const auto sourceName = source.name();
connect(fw, &QFutureWatcher<QList<AppStream::Component>>::finished, this, [this, fw, flatpakInstallation, appstreamIconsPath, sourceName]() {
const auto components = fw->result();
foreach (const AppStream::Component& appstreamComponent, components) {
FlatpakResource *resource = new FlatpakResource(appstreamComponent, flatpakInstallation, this);
resource->setIconPath(appstreamIconsPath);
resource->setOrigin(sourceName);
addResource(resource);
}
if (!m_refreshAppstreamMetadataJobs) {
finishInitialization();
}
fw->deleteLater();
});
}
void FlatpakBackend::loadInstalledApps()
......
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