Merge pull request #248 from ukui/v10sp1-dev

Merge from v10sp1-dev for app search optimization.
This commit is contained in:
iaom 2021-05-31 14:32:33 +08:00 committed by GitHub
commit 63e81d08a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 19 deletions

7
debian/changelog vendored
View File

@ -1,3 +1,10 @@
ukui-search (0.4.0+0530) v101; urgency=medium
* Bug 57129
* 任务 无
-- zhangpengfei <zhangpengfei@kylinos.cn> Sun, 30 May 2021 11:21:37 +0800
ukui-search (0.4.0+0520) v101; urgency=medium
* Bug 55034,55545,55326,55496

View File

@ -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<NameString, QStringList> &inst
}
void AppMatch::softWareCenterSearch(QMap<NameString, QStringList> &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!";
}

View File

@ -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<QStringList> 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<SearchAppThread *>(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<QStringList> 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<QStringList>, appVector));
// Q_EMIT this->searchResultApp(appVector);
}
m_mutex.unlock();
m_installed_apps.clear();

View File

@ -13,27 +13,30 @@ public:
SearchAppThread(QObject * parent = nullptr);
~SearchAppThread() = default;
void startSearch(const QString&);
Q_INVOKABLE void sendResult(const QVector<QStringList> result);
private:
QThreadPool m_pool;
Q_SIGNALS:
void searchResultApp(const QVector<QStringList>&);
void searchResultApp(const QVector<QStringList>);
};
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<NameString, QStringList> m_installed_apps;
QMap<NameString, QStringList> m_uninstalled_apps;
Q_SIGNALS:
void searchResultApp(const QVector<QStringList>&);
//Q_SIGNALS:
// void searchResultApp(const QVector<QStringList>&);
};
}