From 64082237608fee195f0a3e570398170b800bd2ab Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Thu, 14 Jul 2022 19:01:56 +0800 Subject: [PATCH] Fix the error count of launch times. Modify the enqueue operation of app queue. --- .../app-db-manager.cpp | 16 +++++++---- ukui-search-app-data-service/app-db-manager.h | 2 +- .../pending-app-info-queue.cpp | 28 ++++++++++++------- .../pending-app-info-queue.h | 2 +- .../pending-app-info.h | 16 +++++++++-- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index b5b267c..58d473b 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -709,8 +709,8 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopfd) "MODIFYED_TIME='%0'," "LOCAL_NAME='%1'," "NAME_EN='%2'," - "NAME_ZH='%3'" - ",PINYIN_NAME='%4'," + "NAME_ZH='%3'," + "PINYIN_NAME='%4'," "FIRST_LETTER_OF_PINYIN='%5'," "FIRST_LETTER_ALL='%6'," "ICON='%7'," @@ -753,14 +753,15 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopfd) return res; } -bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp) +bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp, int num) { + qDebug() << "launch times will add:" << num; bool res(true); QSqlQuery sql(m_database); QString cmd = QString("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH='%1'").arg(desktopfp); if (sql.exec(cmd)) { if (sql.next()) { - int launchTimes = sql.value(0).toInt() + 1; + int launchTimes = sql.value(0).toInt() + num; cmd = QString("UPDATE appInfo SET MODIFYED_TIME='%0', LAUNCH_TIMES=%1, LAUNCHED=%2 WHERE DESKTOP_FILE_PATH='%3'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")) .arg(launchTimes) @@ -774,7 +775,7 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp) result.desktopPath = desktopfp; result.launchTimes = launchTimes; Q_EMIT this->appDBItemUpdate(result); - qDebug() << "app database update " << desktopfp << "launch times success!"; + qDebug() << "app database update:" << desktopfp << "launch times:" << launchTimes << "success!"; } } else { qWarning() << "Failed to exec next!" << cmd; @@ -929,12 +930,15 @@ void AppDBManager::updateLocaleData(const QString &desktopfp) void AppDBManager::updateLaunchTimes(const QString &desktopfp) { PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateLaunchTimes); + item.setLaunchWillAdd(true); + item.setLaunchTimes(1); PendingAppInfoQueue::getAppInfoQueue().enqueue(item); } void AppDBManager::updateFavoritesState(const QString &desktopfp, int num) { - PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateFavorites, num); + PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateFavorites); + item.setFavorites(num); PendingAppInfoQueue::getAppInfoQueue().enqueue(item); } diff --git a/ukui-search-app-data-service/app-db-manager.h b/ukui-search-app-data-service/app-db-manager.h index b663d38..bb444b0 100644 --- a/ukui-search-app-data-service/app-db-manager.h +++ b/ukui-search-app-data-service/app-db-manager.h @@ -67,7 +67,7 @@ public: bool handleDBItemDelete(const QString &desktopfd); bool handleLocaleDataUpdate(const QString &desktopPath); - bool handleLaunchTimesUpdate(const QString &desktopfp); + bool handleLaunchTimesUpdate(const QString &desktopfp, int num); bool handleFavoritesStateUpdate(const QString &desktopfp, int num); bool handleTopStateUpdate(const QString &desktopfp, int num); bool handleLockStateUpdate(const QString &desktopfp, int num); diff --git a/ukui-search-app-data-service/pending-app-info-queue.cpp b/ukui-search-app-data-service/pending-app-info-queue.cpp index a3956ab..0bd94e3 100644 --- a/ukui-search-app-data-service/pending-app-info-queue.cpp +++ b/ukui-search-app-data-service/pending-app-info-queue.cpp @@ -19,18 +19,20 @@ void PendingAppInfoQueue::enqueue(const PendingAppInfo &appInfo) if (index == -1) { m_cache << appInfo; } else { - //已插入项操作类型为对某字段更新 - if (m_cache[index].handleType() > PendingAppInfo::HandleType::UpdateAll) { - if (appInfo.handleType() > PendingAppInfo::HandleType::UpdateAll) { - m_cache[index].merge(appInfo); - } else { - m_cache[index].setHandleType(appInfo); - } - } else { - //已插入项操作类型为对全部字段进行增删改时,设置为优先级高的操作类型 + //只要操作类型为delete,直接覆盖 + if (m_cache[index].handleType() == PendingAppInfo::HandleType::Delete + or appInfo.handleType() == PendingAppInfo::HandleType::Delete) { + m_cache[index].setHandleType(PendingAppInfo::HandleType::Delete); + + //已插入项操作类型为对所有desktop文件相关数据进行操作 + } else if (m_cache[index].handleType() < PendingAppInfo::HandleType::UpdateLocaleData + and appInfo.handleType() < PendingAppInfo::HandleType::UpdateLocaleData) { + //设置为优先级高的操作类型 if (m_cache[index].handleType() > appInfo.handleType()) { m_cache[index].setHandleType(appInfo); } + } else { + m_cache[index].merge(appInfo); } } @@ -116,11 +118,17 @@ void PendingAppInfoQueue::processCache() break; } } else { + if (handleTypes & PendingAppInfo::HandleType::Insert) { + AppDBManager::getInstance()->handleDBItemInsert(info.path()); + } + if (handleTypes & PendingAppInfo::HandleType::UpdateAll) { + AppDBManager::getInstance()->handleDBItemUpdate(info.path()); + } if (handleTypes & PendingAppInfo::HandleType::UpdateLocaleData) { AppDBManager::getInstance()->handleLocaleDataUpdate(info.path()); } if (handleTypes & PendingAppInfo::HandleType::UpdateLaunchTimes) { - AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path()); + AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes()); } if (handleTypes & PendingAppInfo::HandleType::UpdateFavorites) { AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState()); diff --git a/ukui-search-app-data-service/pending-app-info-queue.h b/ukui-search-app-data-service/pending-app-info-queue.h index df1d11c..fa1e242 100644 --- a/ukui-search-app-data-service/pending-app-info-queue.h +++ b/ukui-search-app-data-service/pending-app-info-queue.h @@ -15,7 +15,7 @@ class PendingAppInfoQueue : public QThread Q_OBJECT public: static PendingAppInfoQueue &getAppInfoQueue(); - void enqueue(const PendingAppInfo& appInfo); + void enqueue(const PendingAppInfo &appInfo); protected: void run() override; diff --git a/ukui-search-app-data-service/pending-app-info.h b/ukui-search-app-data-service/pending-app-info.h index 8fd0639..51e11c7 100644 --- a/ukui-search-app-data-service/pending-app-info.h +++ b/ukui-search-app-data-service/pending-app-info.h @@ -22,23 +22,30 @@ public: Q_DECLARE_FLAGS(HandleTypes, HandleType) PendingAppInfo() = default; - PendingAppInfo(QString desktopfp, HandleTypes type, int favorites = -1, int top = -1, int lock = -1) + PendingAppInfo(QString desktopfp, HandleTypes type, int favorites = -1, int top = -1, int lock = -1, bool addLaunch = false, int launchTimes = 0) : m_desktopfp(desktopfp), m_handleType(type), m_favoritesState(favorites), m_topState(top), - m_lockState(lock) {} + m_lockState(lock), + m_willAddLaunch(addLaunch), + m_launchTimes(launchTimes) {} QString path() const {return m_desktopfp;} HandleTypes handleType() const {return m_handleType;} int favoritesState() const {return m_favoritesState;} int topState() const {return m_topState;} int lockState() const {return m_lockState;} + int launchTimes() const {return m_launchTimes;} + bool willAddLunchTimes() const {return m_willAddLaunch;} void setHandleType(const PendingAppInfo & info) {m_handleType = info.handleType();} + void setHandleType(HandleTypes type) {m_handleType = type;} void setFavorites(int favoritesState) {m_favoritesState = favoritesState;} void setTop(int top) {m_topState = top;} void setLock(int lock) {m_lockState = lock;} + void setLaunchWillAdd(bool willAdd) {m_willAddLaunch = willAdd;} + void setLaunchTimes(int times) {m_launchTimes = times;} void merge(const PendingAppInfo &info) { m_handleType |= info.handleType(); @@ -54,6 +61,9 @@ public: if (info.lockState() != -1) { m_lockState = info.lockState(); } + if (info.willAddLunchTimes()) { + m_launchTimes++; + } } bool operator ==(const PendingAppInfo& rhs) const { @@ -65,6 +75,8 @@ private: int m_favoritesState; int m_topState; int m_lockState; + bool m_willAddLaunch; + int m_launchTimes; }; }