Fix the error count of launch times.

Modify the enqueue operation of app queue.
This commit is contained in:
JunjieBai 2022-07-14 19:01:56 +08:00
parent 720ac7304c
commit 6408223760
5 changed files with 44 additions and 20 deletions

View File

@ -709,8 +709,8 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopfd)
"MODIFYED_TIME='%0'," "MODIFYED_TIME='%0',"
"LOCAL_NAME='%1'," "LOCAL_NAME='%1',"
"NAME_EN='%2'," "NAME_EN='%2',"
"NAME_ZH='%3'" "NAME_ZH='%3',"
",PINYIN_NAME='%4'," "PINYIN_NAME='%4',"
"FIRST_LETTER_OF_PINYIN='%5'," "FIRST_LETTER_OF_PINYIN='%5',"
"FIRST_LETTER_ALL='%6'," "FIRST_LETTER_ALL='%6',"
"ICON='%7'," "ICON='%7',"
@ -753,14 +753,15 @@ bool AppDBManager::handleDBItemUpdate(const QString &desktopfd)
return res; 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); bool res(true);
QSqlQuery sql(m_database); QSqlQuery sql(m_database);
QString cmd = QString("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH='%1'").arg(desktopfp); QString cmd = QString("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH='%1'").arg(desktopfp);
if (sql.exec(cmd)) { if (sql.exec(cmd)) {
if (sql.next()) { 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'") 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(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(launchTimes) .arg(launchTimes)
@ -774,7 +775,7 @@ bool AppDBManager::handleLaunchTimesUpdate(const QString &desktopfp)
result.desktopPath = desktopfp; result.desktopPath = desktopfp;
result.launchTimes = launchTimes; result.launchTimes = launchTimes;
Q_EMIT this->appDBItemUpdate(result); Q_EMIT this->appDBItemUpdate(result);
qDebug() << "app database update " << desktopfp << "launch times success!"; qDebug() << "app database update:" << desktopfp << "launch times:" << launchTimes << "success!";
} }
} else { } else {
qWarning() << "Failed to exec next!" << cmd; qWarning() << "Failed to exec next!" << cmd;
@ -929,12 +930,15 @@ void AppDBManager::updateLocaleData(const QString &desktopfp)
void AppDBManager::updateLaunchTimes(const QString &desktopfp) void AppDBManager::updateLaunchTimes(const QString &desktopfp)
{ {
PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateLaunchTimes); PendingAppInfo item(desktopfp, PendingAppInfo::HandleType::UpdateLaunchTimes);
item.setLaunchWillAdd(true);
item.setLaunchTimes(1);
PendingAppInfoQueue::getAppInfoQueue().enqueue(item); PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
} }
void AppDBManager::updateFavoritesState(const QString &desktopfp, int num) 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); PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
} }

View File

@ -67,7 +67,7 @@ public:
bool handleDBItemDelete(const QString &desktopfd); bool handleDBItemDelete(const QString &desktopfd);
bool handleLocaleDataUpdate(const QString &desktopPath); 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 handleFavoritesStateUpdate(const QString &desktopfp, int num);
bool handleTopStateUpdate(const QString &desktopfp, int num); bool handleTopStateUpdate(const QString &desktopfp, int num);
bool handleLockStateUpdate(const QString &desktopfp, int num); bool handleLockStateUpdate(const QString &desktopfp, int num);

View File

@ -19,18 +19,20 @@ void PendingAppInfoQueue::enqueue(const PendingAppInfo &appInfo)
if (index == -1) { if (index == -1) {
m_cache << appInfo; m_cache << appInfo;
} else { } else {
//已插入项操作类型为对某字段更新 //只要操作类型为delete直接覆盖
if (m_cache[index].handleType() > PendingAppInfo::HandleType::UpdateAll) { if (m_cache[index].handleType() == PendingAppInfo::HandleType::Delete
if (appInfo.handleType() > PendingAppInfo::HandleType::UpdateAll) { or appInfo.handleType() == PendingAppInfo::HandleType::Delete) {
m_cache[index].merge(appInfo); m_cache[index].setHandleType(PendingAppInfo::HandleType::Delete);
} else {
m_cache[index].setHandleType(appInfo); //已插入项操作类型为对所有desktop文件相关数据进行操作
} } else if (m_cache[index].handleType() < PendingAppInfo::HandleType::UpdateLocaleData
} else { and appInfo.handleType() < PendingAppInfo::HandleType::UpdateLocaleData) {
//已插入项操作类型为对全部字段进行增删改时,设置为优先级高的操作类型 //设置为优先级高的操作类型
if (m_cache[index].handleType() > appInfo.handleType()) { if (m_cache[index].handleType() > appInfo.handleType()) {
m_cache[index].setHandleType(appInfo); m_cache[index].setHandleType(appInfo);
} }
} else {
m_cache[index].merge(appInfo);
} }
} }
@ -116,11 +118,17 @@ void PendingAppInfoQueue::processCache()
break; break;
} }
} else { } 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) { if (handleTypes & PendingAppInfo::HandleType::UpdateLocaleData) {
AppDBManager::getInstance()->handleLocaleDataUpdate(info.path()); AppDBManager::getInstance()->handleLocaleDataUpdate(info.path());
} }
if (handleTypes & PendingAppInfo::HandleType::UpdateLaunchTimes) { if (handleTypes & PendingAppInfo::HandleType::UpdateLaunchTimes) {
AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path()); AppDBManager::getInstance()->handleLaunchTimesUpdate(info.path(), info.launchTimes());
} }
if (handleTypes & PendingAppInfo::HandleType::UpdateFavorites) { if (handleTypes & PendingAppInfo::HandleType::UpdateFavorites) {
AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState()); AppDBManager::getInstance()->handleFavoritesStateUpdate(info.path(), info.favoritesState());

View File

@ -15,7 +15,7 @@ class PendingAppInfoQueue : public QThread
Q_OBJECT Q_OBJECT
public: public:
static PendingAppInfoQueue &getAppInfoQueue(); static PendingAppInfoQueue &getAppInfoQueue();
void enqueue(const PendingAppInfo& appInfo); void enqueue(const PendingAppInfo &appInfo);
protected: protected:
void run() override; void run() override;

View File

@ -22,23 +22,30 @@ public:
Q_DECLARE_FLAGS(HandleTypes, HandleType) Q_DECLARE_FLAGS(HandleTypes, HandleType)
PendingAppInfo() = default; 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_desktopfp(desktopfp),
m_handleType(type), m_handleType(type),
m_favoritesState(favorites), m_favoritesState(favorites),
m_topState(top), m_topState(top),
m_lockState(lock) {} m_lockState(lock),
m_willAddLaunch(addLaunch),
m_launchTimes(launchTimes) {}
QString path() const {return m_desktopfp;} QString path() const {return m_desktopfp;}
HandleTypes handleType() const {return m_handleType;} HandleTypes handleType() const {return m_handleType;}
int favoritesState() const {return m_favoritesState;} int favoritesState() const {return m_favoritesState;}
int topState() const {return m_topState;} int topState() const {return m_topState;}
int lockState() const {return m_lockState;} 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(const PendingAppInfo & info) {m_handleType = info.handleType();}
void setHandleType(HandleTypes type) {m_handleType = type;}
void setFavorites(int favoritesState) {m_favoritesState = favoritesState;} void setFavorites(int favoritesState) {m_favoritesState = favoritesState;}
void setTop(int top) {m_topState = top;} void setTop(int top) {m_topState = top;}
void setLock(int lock) {m_lockState = lock;} 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) void merge(const PendingAppInfo &info)
{ {
m_handleType |= info.handleType(); m_handleType |= info.handleType();
@ -54,6 +61,9 @@ public:
if (info.lockState() != -1) { if (info.lockState() != -1) {
m_lockState = info.lockState(); m_lockState = info.lockState();
} }
if (info.willAddLunchTimes()) {
m_launchTimes++;
}
} }
bool operator ==(const PendingAppInfo& rhs) const { bool operator ==(const PendingAppInfo& rhs) const {
@ -65,6 +75,8 @@ private:
int m_favoritesState; int m_favoritesState;
int m_topState; int m_topState;
int m_lockState; int m_lockState;
bool m_willAddLaunch;
int m_launchTimes;
}; };
} }