解决当搜索UI关闭后未正确停止插件搜索线程的问题;解决遍历搜索时文件搜索插件长时间cpu占用较高的问题。

This commit is contained in:
iaom 2023-06-14 14:08:55 +08:00
parent 0b6b7ef9a0
commit 275f69dd3f
2 changed files with 13 additions and 25 deletions

View File

@ -48,10 +48,10 @@ void SearchResultManager::stopSearch()
{ {
if(m_getResultThread->isRunning()) { if(m_getResultThread->isRunning()) {
m_getResultThread->stop(); m_getResultThread->stop();
SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_pluginId);
plugin->stopSearch();
qDebug() << m_pluginId << "stopped";
} }
SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_pluginId);
plugin->stopSearch();
qDebug() << m_pluginId << "stopped";
} }
void SearchResultManager::initConnections() void SearchResultManager::initConnections()

View File

@ -541,7 +541,14 @@ void DirectSearch::run() {
} }
bfs.enqueue(i.absoluteFilePath()); bfs.enqueue(i.absoluteFilePath());
} }
match(i); SearchManager::m_mutexDir.lock();
if(m_uniqueSymbol == SearchManager::uniqueSymbolDir) {
match(i);
SearchManager::m_mutexDir.unlock();
} else {
SearchManager::m_mutexDir.unlock();
return;
}
} }
} }
} }
@ -549,29 +556,10 @@ void DirectSearch::run() {
void DirectSearch::match(const QFileInfo &info) void DirectSearch::match(const QFileInfo &info)
{ {
if(info.fileName().contains(m_keyword, Qt::CaseInsensitive)) { if(info.fileName().contains(m_keyword, Qt::CaseInsensitive)) {
if((info.isDir() && m_value == DIR_SEARCH_VALUE)) { if((info.isDir() && m_value == DIR_SEARCH_VALUE) || (info.isFile() && m_value == FILE_SEARCH_VALUE)) {
SearchPluginIface::ResultInfo ri; SearchPluginIface::ResultInfo ri;
if(SearchManager::creatResultInfo(ri,info.absoluteFilePath())) { if(SearchManager::creatResultInfo(ri,info.absoluteFilePath())) {
SearchManager::m_mutexDir.lock(); m_searchResult->enqueue(ri);
if(m_uniqueSymbol == SearchManager::uniqueSymbolDir) {
m_searchResult->enqueue(ri);
SearchManager::m_mutexDir.unlock();
} else {
SearchManager::m_mutexDir.unlock();
return;
}
}
} else if (info.isFile() && m_value == FILE_SEARCH_VALUE) {
SearchPluginIface::ResultInfo ri;
if(SearchManager::creatResultInfo(ri,info.absoluteFilePath())) {
SearchManager::m_mutexFile.lock();
if(m_uniqueSymbol == SearchManager::uniqueSymbolFile) {
m_searchResult->enqueue(ri);
SearchManager::m_mutexFile.unlock();
} else {
SearchManager::m_mutexFile.unlock();
return;
}
} }
} }
} }