diff --git a/deblistmodel.cpp b/deblistmodel.cpp index 96debd80727de4279a3fe7b22731fd4f26f9d8b9..7c8dd978916011f2183687fdf7e945c9571bddea 100644 --- a/deblistmodel.cpp +++ b/deblistmodel.cpp @@ -381,7 +381,14 @@ void DebListModel::onDependsInstallTransactionFinished() if (ret) bumpInstallIndex(); else + { + // dependencies are installed and the apt cache has changed, + // invalidate the cached depends status (and reload the cache) so + // installNextDeb() re-checks against the fresh package database + // instead of installing the same dependencies again. + m_packagesManager->resetPackageDependsStatus(m_operatingIndex); installNextDeb(); + } } void DebListModel::installNextDeb() @@ -392,7 +399,8 @@ void DebListModel::installNextDeb() if (isDpkgRunning()) { qDebug() << "dpkg running, waitting..."; - QTimer::singleShot(1000 * 5, this, &DebListModel::installNextDeb); + // 缩短检查的时间,每隔1S检查当前dpkg是否正在运行,减少安装前的等待。 + QTimer::singleShot(1000 * 1, this, &DebListModel::installNextDeb); return; } @@ -402,8 +410,17 @@ void DebListModel::installNextDeb() auto const backend = m_packagesManager->m_backendFuture.result(); Transaction *trans = nullptr; - // reset package depends status - m_packagesManager->resetPackageDependsStatus(m_operatingIndex); + // If package is first package and its depends status is already cached, + // nothing has been installed yet, so the apt cache is unchanged. + // Skip resetPackageDependsStatus() to avoid the long UI freeze caused + // by the synchronous reloadCache() and the depends re-check. + const bool isFirstPackageAndCached = (0 == m_operatingIndex) && m_packagesManager->cachedPackageDependStatus(m_operatingIndex); + if (!isFirstPackageAndCached) + { + // reset package depends status + // The apt backend cache may changed, refresh package status. + m_packagesManager->resetPackageDependsStatus(m_operatingIndex); + } // check available dependencies const auto dependsStat = m_packagesManager->packageDependsStatus(m_operatingIndex); diff --git a/packagesmanager.cpp b/packagesmanager.cpp index 524f607dd52c8590c774b3c402afa2d3f9cbb8ce..d71b9f398d20fc6ddb2f10a2d2db7af4ceb6e743 100644 --- a/packagesmanager.cpp +++ b/packagesmanager.cpp @@ -366,6 +366,11 @@ PackageDependsStatus PackagesManager::packageDependsStatus(const int index) return ret; } +bool PackagesManager::cachedPackageDependStatus(const int index) const +{ + return m_packageDependsStatus.contains(index); +} + const QString PackagesManager::packageInstalledVersion(const int index) { Q_ASSERT(m_packageInstallStatus.contains(index)); diff --git a/packagesmanager.h b/packagesmanager.h index 9d04255bff550d867de9cc4322d548482f59e159..72cf4d8a1381659c5b40c0ecdbfe74cadf983d16 100644 --- a/packagesmanager.h +++ b/packagesmanager.h @@ -81,6 +81,7 @@ public: const ConflictResult isConflictSatisfy(const QString &arch, const QList &conflicts); int packageInstallStatus(const int index); PackageDependsStatus packageDependsStatus(const int index); + bool cachedPackageDependStatus(const int index) const; const QString packageInstalledVersion(const int index); const QStringList packageAvailableDepends(const int index); void packageCandidateChoose(QSet &choosed_set, const QString &debArch, const QList &dependsList);