Commit 2fd22c34 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Fetch all dependencies in a single transaction

PackageKit would choke on big updates otherwise
parent 2c131e8d
...@@ -515,9 +515,29 @@ void PackageKitBackend::fetchDetails(const QString& pkgid) ...@@ -515,9 +515,29 @@ void PackageKitBackend::fetchDetails(const QString& pkgid)
void PackageKitBackend::performDetailsFetch() void PackageKitBackend::performDetailsFetch()
{ {
Q_ASSERT(!m_packageNamesToFetchDetails.isEmpty()); Q_ASSERT(!m_packageNamesToFetchDetails.isEmpty());
PackageKit::Transaction* transaction = PackageKit::Daemon::getDetails(m_packageNamesToFetchDetails.toList()); const auto ids = m_packageNamesToFetchDetails.toList();
PackageKit::Transaction* transaction = PackageKit::Daemon::getDetails(ids);
connect(transaction, &PackageKit::Transaction::details, this, &PackageKitBackend::packageDetails); connect(transaction, &PackageKit::Transaction::details, this, &PackageKitBackend::packageDetails);
connect(transaction, &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError); connect(transaction, &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError);
QSharedPointer<QMap<QString, int>> packageDependencies(new QMap<QString, int>);
auto trans = PackageKit::Daemon::installPackages(ids, PackageKit::Transaction::TransactionFlagSimulate);
connect(trans, &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError);
connect(trans, &PackageKit::Transaction::package, this, [packageDependencies](PackageKit::Transaction::Info /*info*/, const QString &packageID, const QString &/*summary*/) {
(*packageDependencies)[packageID] += 1;
});
connect(trans, &PackageKit::Transaction::finished, this, [this, packageDependencies](PackageKit::Transaction::Exit /*status*/) {
auto pkgDeps = (*packageDependencies);
for (auto it = pkgDeps.constBegin(), itEnd = pkgDeps.constEnd(); it != itEnd; ++it) {
const auto resources = resourcesByPackageName(PackageKit::Daemon::packageName(it.key()));
for(auto resource : resources) {
auto pkres = qobject_cast<PackageKitResource*>(resource);
pkres->setDependenciesCount(it.value());
}
}
});
} }
void PackageKitBackend::checkDaemonRunning() void PackageKitBackend::checkDaemonRunning()
......
...@@ -169,18 +169,6 @@ void PackageKitResource::fetchDetails() ...@@ -169,18 +169,6 @@ void PackageKitResource::fetchDetails()
m_details.insert(QStringLiteral("fetching"), true);//we add an entry so it's not re-fetched. m_details.insert(QStringLiteral("fetching"), true);//we add an entry so it's not re-fetched.
backend()->fetchDetails(pkgid); backend()->fetchDetails(pkgid);
auto trans = PackageKit::Daemon::installPackages({ pkgid }, PackageKit::Transaction::TransactionFlagSimulate);
connect(trans, &PackageKit::Transaction::package, this, [trans](PackageKit::Transaction::Info /*info*/, const QString &/*packageID*/, const QString &/*summary*/) {
trans->setProperty("dependencies", trans->property("dependencies").toUInt() + 1);
});
connect(trans, &PackageKit::Transaction::finished, this, [this, trans](PackageKit::Transaction::Exit /*status*/) {
auto deps = trans->property("dependencies").toUInt();
if (deps != m_dependenciesCount) {
m_dependenciesCount = deps;
Q_EMIT sizeChanged();
}
});
} }
void PackageKitResource::failedFetchingDetails(PackageKit::Transaction::Error, const QString& msg) void PackageKitResource::failedFetchingDetails(PackageKit::Transaction::Error, const QString& msg)
...@@ -188,6 +176,14 @@ void PackageKitResource::failedFetchingDetails(PackageKit::Transaction::Error, c ...@@ -188,6 +176,14 @@ void PackageKitResource::failedFetchingDetails(PackageKit::Transaction::Error, c
qWarning() << "error fetching details" << msg; qWarning() << "error fetching details" << msg;
} }
void PackageKitResource::setDependenciesCount(uint deps)
{
if (deps != m_dependenciesCount) {
m_dependenciesCount = deps;
Q_EMIT sizeChanged();
}
}
void PackageKitResource::setDetails(const PackageKit::Details & details) void PackageKitResource::setDetails(const PackageKit::Details & details)
{ {
const bool ourDetails = details.packageId() == availablePackageId(); const bool ourDetails = details.packageId() == availablePackageId();
......
...@@ -67,6 +67,7 @@ class PackageKitResource : public AbstractResource ...@@ -67,6 +67,7 @@ class PackageKitResource : public AbstractResource
bool canExecute() const override { return false; } bool canExecute() const override { return false; }
QString sizeDescription() override; QString sizeDescription() override;
void setDependenciesCount(uint count);
public Q_SLOTS: public Q_SLOTS:
void addPackageId(PackageKit::Transaction::Info info, const QString &packageId, bool arch); void addPackageId(PackageKit::Transaction::Info info, const QString &packageId, bool arch);
......
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