perf(app-database-service):optimize the logic of the method which is used to find desktop file.

This commit is contained in:
JunjieBai 2023-08-23 15:35:27 +08:00
parent 597be83dac
commit a8c400cdb0
1 changed files with 43 additions and 33 deletions

View File

@ -1426,10 +1426,18 @@ QString AppDBManager::tranPidToDesktopFp(uint pid)
if (cmdlist.at(i).startsWith("-") || cmdlist.at(i).contains("%")) { if (cmdlist.at(i).startsWith("-") || cmdlist.at(i).contains("%")) {
continue; continue;
} }
if (!QUrl(cmdlist.at(i)).isRelative()) {
continue;
}
exePath = cmdlist.at(i); exePath = cmdlist.at(i);
break; break;
} }
QString desktopFilePath; QString desktopFilePath;
if (exePath.isEmpty()) {
qWarning() << "Can not find the desktop file by pid:" << pid << "because of empty exePath.";
return desktopFilePath;
}
QSqlQuery query(m_database); QSqlQuery query(m_database);
query.setForwardOnly(true); query.setForwardOnly(true);
@ -1535,12 +1543,11 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id)
KWindowInfo info(id.variant().toULongLong(), NET::Properties(), NET::WM2AllProperties); KWindowInfo info(id.variant().toULongLong(), NET::Properties(), NET::WM2AllProperties);
QString desktopFilePath; QString desktopFilePath;
if (info.valid()) { if (info.valid()) {
desktopFilePath = this->tranPidToDesktopFp(info.pid());
if (desktopFilePath.isEmpty()) {
QString classClass = info.windowClassClass(); //the 2nd part of WM_CLASS, specified by the application writer QString classClass = info.windowClassClass(); //the 2nd part of WM_CLASS, specified by the application writer
QSqlQuery query(m_database); QSqlQuery query(m_database);
query.setForwardOnly(true); query.setForwardOnly(true);
query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE EXEC LIKE :classClass OR DESKTOP_FILE_PATH LIKE :classClass OR LOWER(START_UP_WMCLASS)=:windowClassClass"); query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE EXEC LIKE :classClass OR DESKTOP_FILE_PATH LIKE :classClass "
"OR LOWER(START_UP_WMCLASS)=:windowClassClass OR LOWER(LOCAL_NAME)=:windowClassClass");
query.bindValue(":classClass", "%" + classClass + "%"); query.bindValue(":classClass", "%" + classClass + "%");
query.bindValue(":windowClassClass", classClass.toLower()); query.bindValue(":windowClassClass", classClass.toLower());
@ -1572,6 +1579,9 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id)
} else { } else {
qWarning() << "Fail to exec cmd" << query.lastQuery(); qWarning() << "Fail to exec cmd" << query.lastQuery();
} }
if (desktopFilePath.isEmpty()) {
desktopFilePath = this->tranPidToDesktopFp(info.pid());
} }
} else { } else {
qWarning() << "Cannot find desktop flie by WinId:" << id.variant() << "it is invalid" << id.variant().toULongLong(); qWarning() << "Cannot find desktop flie by WinId:" << id.variant() << "it is invalid" << id.variant().toULongLong();