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 committed by iaom
parent 530b3c0cbe
commit bc6a5bcbbf
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("%")) {
continue;
}
if (!QUrl(cmdlist.at(i)).isRelative()) {
continue;
}
exePath = cmdlist.at(i);
break;
}
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);
query.setForwardOnly(true);
@ -1535,12 +1543,11 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id)
KWindowInfo info(id.variant().toULongLong(), NET::Properties(), NET::WM2AllProperties);
QString desktopFilePath;
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
QSqlQuery query(m_database);
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(":windowClassClass", classClass.toLower());
@ -1572,6 +1579,9 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id)
} else {
qWarning() << "Fail to exec cmd" << query.lastQuery();
}
if (desktopFilePath.isEmpty()) {
desktopFilePath = this->tranPidToDesktopFp(info.pid());
}
} else {
qWarning() << "Cannot find desktop flie by WinId:" << id.variant() << "it is invalid" << id.variant().toULongLong();