From f36c3b0bf7c68cb6aa5f79c9805cc09f7420e544 Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Sun, 30 May 2021 11:28:04 +0800 Subject: [PATCH 1/2] Optimezed function of app search. --- libsearch/appsearch/app-match.cpp | 9 +++++---- src/search-app-thread.cpp | 29 ++++++++++++++++++----------- src/search-app-thread.h | 11 +++++++---- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/libsearch/appsearch/app-match.cpp b/libsearch/appsearch/app-match.cpp index 0e0269e..aca6503 100644 --- a/libsearch/appsearch/app-match.cpp +++ b/libsearch/appsearch/app-match.cpp @@ -46,6 +46,7 @@ AppMatch::AppMatch(QObject *parent) : QThread(parent) if(!m_interFace->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); } + m_interFace->setTimeout(200); qDebug() << "AppMatch is new"; } @@ -277,10 +278,10 @@ void AppMatch::appNameMatch(QString appname, QMap &inst } void AppMatch::softWareCenterSearch(QMap &softwarereturn) { - if(m_interFace->timeout() != -1) { - qWarning() << "softWareCente Dbus is timeout !"; - return; - } +// if(m_interFace->timeout() != -1) { +// qWarning() << "softWareCente Dbus is timeout !"; +// return; +// } slotDBusCallFinished(softwarereturn); qDebug() << "softWareCenter match app is successful!"; } diff --git a/src/search-app-thread.cpp b/src/search-app-thread.cpp index aadea1e..c5d482b 100644 --- a/src/search-app-thread.cpp +++ b/src/search-app-thread.cpp @@ -5,21 +5,32 @@ size_t uniqueSymbol = 0; QMutex m_mutex; SearchAppThread::SearchAppThread(QObject *parent) : QObject(parent) { - m_pool.setMaxThreadCount(1); + m_pool.setMaxThreadCount(2); m_pool.setExpiryTimeout(1000); } void SearchAppThread::startSearch(const QString & keyword) { + m_mutex.lock(); + ++uniqueSymbol; + m_mutex.unlock(); SearchApp *appsearch; - appsearch = new SearchApp(keyword); + appsearch = new SearchApp(keyword,uniqueSymbol,this); // appsearch->setKeyword(keyword); - connect(appsearch, &SearchApp::searchResultApp, this, &SearchAppThread::searchResultApp); +// connect(appsearch, &SearchApp::searchResultApp, this, &SearchAppThread::searchResultApp); m_pool.start(appsearch); } +void SearchAppThread::sendResult(const QVector result) +{ + Q_EMIT this->searchResultApp(result); +} -SearchApp::SearchApp(const QString& keyword, QObject * parent) : QObject(parent) { + +SearchApp::SearchApp(const QString& keyword, size_t uniqueSymbol, QObject * parent) : QObject(parent) { + this->setAutoDelete(true); + m_searchappThread = qobject_cast(parent); m_keyword = keyword; + m_uniqueSymbol = uniqueSymbol; } SearchApp::~SearchApp() { @@ -35,11 +46,6 @@ SearchApp::~SearchApp() { //} void SearchApp::run() { - m_mutex.lock(); - size_t tmp_uniqueSymbol; - uniqueSymbol++; - tmp_uniqueSymbol = uniqueSymbol; - m_mutex.unlock(); //nameList:应用名,pathList:已安装的是.desktop路径,未安装为空,iconList:已安装的是图标名,未安装的是图标路径 QStringList nameList, pathList, iconList, descList; QVector appVector; @@ -70,8 +76,9 @@ void SearchApp::run() { appVector.append(iconList); appVector.append(descList); m_mutex.lock(); - if (tmp_uniqueSymbol == uniqueSymbol) { - Q_EMIT this->searchResultApp(appVector); + if (m_uniqueSymbol == uniqueSymbol) { + QMetaObject::invokeMethod(m_searchappThread, "sendResult", Q_ARG(const QVector, appVector)); +// Q_EMIT this->searchResultApp(appVector); } m_mutex.unlock(); m_installed_apps.clear(); diff --git a/src/search-app-thread.h b/src/search-app-thread.h index 46cf491..9497ee5 100644 --- a/src/search-app-thread.h +++ b/src/search-app-thread.h @@ -13,27 +13,30 @@ public: SearchAppThread(QObject * parent = nullptr); ~SearchAppThread() = default; void startSearch(const QString&); + Q_INVOKABLE void sendResult(const QVector result); private: QThreadPool m_pool; Q_SIGNALS: - void searchResultApp(const QVector&); + void searchResultApp(const QVector); }; class SearchApp : public QObject, public QRunnable { Q_OBJECT public: - SearchApp(const QString& keyword, QObject * parent = nullptr); + SearchApp(const QString& keyword, size_t uniqueSymbol, QObject * parent = nullptr); ~SearchApp(); // void setKeyword(const QString&); protected: void run() override; private: + SearchAppThread *m_searchappThread = nullptr; QString m_keyword; + size_t m_uniqueSymbol; QMap m_installed_apps; QMap m_uninstalled_apps; -Q_SIGNALS: - void searchResultApp(const QVector&); +//Q_SIGNALS: +// void searchResultApp(const QVector&); }; } From 79a2fdcce52798ebe4ca63362b0a23f8fa27e8dd Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Sun, 30 May 2021 11:28:23 +0800 Subject: [PATCH 2/2] Update changelog. --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 7f17c1f..28cde68 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +ukui-search (0.4.0+0530) v101; urgency=medium + + * Bug 57129 + * 任务 无 + + -- zhangpengfei Sun, 30 May 2021 11:21:37 +0800 + ukui-search (0.4.0+0520) v101; urgency=medium * Bug 55034,55545,55326,55496