From 21597e58c47e8609cac2fc9cf205d1c9b992a988 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Wed, 25 Jan 2023 15:07:34 +0300 Subject: [PATCH] UI: Programs: Optimize app info loading --- src/ui/appinfo/appinfo.cpp | 4 +++- src/ui/appinfo/appinfocache.cpp | 11 ++++++++--- src/ui/appinfo/appinfojob.h | 2 +- src/ui/appinfo/appinfoutil.cpp | 5 ++++- src/ui/util/fileutil.cpp | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ui/appinfo/appinfo.cpp b/src/ui/appinfo/appinfo.cpp index 7f056141..dcc087d6 100644 --- a/src/ui/appinfo/appinfo.cpp +++ b/src/ui/appinfo/appinfo.cpp @@ -9,5 +9,7 @@ QString AppInfo::filePath(const QString &appPath) const bool AppInfo::isFileModified(const QString &appPath) const { - return fileModTime != AppInfoUtil::fileModTime(filePath(appPath)); + const auto appFileModTime = AppInfoUtil::fileModTime(filePath(appPath)); + + return appFileModTime.isValid() && appFileModTime != fileModTime; } diff --git a/src/ui/appinfo/appinfocache.cpp b/src/ui/appinfo/appinfocache.cpp index dc091cf7..6cda6018 100644 --- a/src/ui/appinfo/appinfocache.cpp +++ b/src/ui/appinfo/appinfocache.cpp @@ -66,17 +66,22 @@ AppInfo AppInfoCache::appInfo(const QString &appPath) AppInfo *appInfo = m_cache.object(appPath); bool lookupRequired = false; + auto appInfoManager = IoC(); + if (!appInfo) { appInfo = new AppInfo(); m_cache.insert(appPath, appInfo, 1); - lookupRequired = true; - } else { + + lookupRequired = !appInfoManager->loadInfoFromDb(appPath, *appInfo); + } + + if (!lookupRequired) { lookupRequired = appInfo->isFileModified(appPath); } if (lookupRequired) { - IoC()->lookupAppInfo(appPath); + appInfoManager->lookupAppInfo(appPath); } return *appInfo; diff --git a/src/ui/appinfo/appinfojob.h b/src/ui/appinfo/appinfojob.h index 05266011..296e50df 100644 --- a/src/ui/appinfo/appinfojob.h +++ b/src/ui/appinfo/appinfojob.h @@ -10,7 +10,7 @@ class AppInfoJob : public WorkerJob public: explicit AppInfoJob(const QString &appPath); - QString appPath() const { return text; } + const QString &appPath() const { return text; } public: AppInfo appInfo; diff --git a/src/ui/appinfo/appinfoutil.cpp b/src/ui/appinfo/appinfoutil.cpp index 7acf4390..c29abd20 100644 --- a/src/ui/appinfo/appinfoutil.cpp +++ b/src/ui/appinfo/appinfoutil.cpp @@ -182,7 +182,10 @@ bool getInfo(const QString &appPath, AppInfo &appInfo) // File modification time appInfo.fileModTime = FileUtil::fileModTime(path); - const bool ok = extractVersionInfo(path, appInfo); + const bool ok = appInfo.fileModTime.isValid(); + if (ok) { + extractVersionInfo(path, appInfo); + } revertWow64FsRedirection(wow64FsRedir); diff --git a/src/ui/util/fileutil.cpp b/src/ui/util/fileutil.cpp index 91e0915e..87cd7be3 100644 --- a/src/ui/util/fileutil.cpp +++ b/src/ui/util/fileutil.cpp @@ -214,7 +214,7 @@ bool writeFileData(const QString &filePath, const QByteArray &data) QDateTime fileModTime(const QString &filePath) { - QFileInfo fi(filePath); + const QFileInfo fi(filePath); return fi.lastModified( #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) QTimeZone::UTC