Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 90 additions & 5 deletions src/controller/helpermanager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -11,9 +11,40 @@
#include "controller/search_db.h"
#include "view/jscontext.h"

#include <QDBusMessage>

Check warning on line 14 in src/controller/helpermanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusMessage> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtDBus>

Check warning on line 15 in src/controller/helpermanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtDBus> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusConnection>

Check warning on line 16 in src/controller/helpermanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>

Check warning on line 17 in src/controller/helpermanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace {

bool parseAppLangFromMdPath(const QString &path, QString &appName, QString &lang)
{
if (path.contains("video-guide")) {
return false;
}

const QStringList list = path.split("/");
if (list.count() < 4) {
return false;
}

if (systemType.contains(list.at(list.count() - 4))) {
lang = list.at(list.count() - 2);
appName = list.at(list.count() - 3);
return true;
}

if (list.contains("application") || list.contains("system")) {
lang = list.at(list.count() - 2);
appName = list.at(list.count() - 4);
return true;
}

return false;
}

} // namespace

helperManager::helperManager(QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -165,6 +196,8 @@
qCDebug(app) << "File changed:" << kVideoConfigPath << "modifyTime:" << modifyTime;
}

reconcileIncompleteIndex(mapFile, mapNow);

QStringList deleteList;
QStringList addList;
QStringList addTime;
Expand All @@ -177,6 +210,48 @@
handleDb(deleteList, addList, addTime);
}

void helperManager::reconcileIncompleteIndex(QMap<QString, QString> &mapFile,
const QMap<QString, QString> &mapNow)
{
QStringList stalePaths;

for (auto it = mapFile.constBegin(); it != mapFile.constEnd(); ++it) {
const QString &mdPath = it.key();
if (!mapNow.contains(mdPath)) {
continue;
}

if (mdPath == kVideoConfigPath) {
if (dbObj->searchEntryCount("video-guide", "zh_CN") == 0
|| dbObj->searchEntryCount("video-guide", "en_US") == 0) {
qCWarning(app) << "Incomplete video-guide index, will rebuild:" << mdPath;
stalePaths.append(mdPath);
}
continue;
}

QString appName;
QString lang;
if (!parseAppLangFromMdPath(mdPath, appName, lang)) {
continue;
}

if (dbObj->searchEntryCount(appName, lang) == 0) {
qCWarning(app) << "Incomplete search index, will rebuild:"
<< mdPath << "app:" << appName << "lang:" << lang;
stalePaths.append(mdPath);
}
}

if (!stalePaths.isEmpty()) {
dbObj->deleteFilesTimeEntry(stalePaths);
for (const QString &path : stalePaths) {
mapFile.remove(path);
}
qCDebug(app) << "Cleared stale filetime entries:" << stalePaths.size();
}
}

void helperManager::initConnect()
{
qCDebug(app) << "initConnect";
Expand Down Expand Up @@ -288,15 +363,18 @@
}
}
}
QFileInfo videoFileInfo(kVideoConfigPath);
if (videoFileInfo.exists()) {
dbObj->insertFileTimeEntry(kVideoConfigPath,
videoFileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss.zzz"));
}
}

QStringList list = handlePriority(tmpAddList);
qCDebug(app) << "addList:" << list;

if (!list.isEmpty() && !addTime.isEmpty()) {
qCDebug(app) << "addTime:" << addTime;
dbObj->insertFilesTimeEntry(tmpAddList, addTime);
//通过JS层函数来完成md转html, 然后解析html内所有文本内容
if (!list.isEmpty()) {
// filetime 在 onRecvParseMsg 写入 search 成功之后;此处仅触发 md 解析
if (jsObj && m_webView) {
QString strChange = list.join(",");
qCDebug(app) << strChange;
Expand Down Expand Up @@ -527,6 +605,13 @@
if (!invalid_entry) {
dbObj->addSearchEntry(appName, lang, anchors, anchorInitialList, anchorSpellList, anchorIdList, contents, path);
qCDebug(app) << "addSearchEntry end";

QFileInfo fileInfo(path);
if (fileInfo.exists()) {
dbObj->insertFileTimeEntry(path,
fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss.zzz"));
qCDebug(app) << "insertFileTimeEntry after addSearchEntry:" << path;
}
}
//获取内容解析返回 重置定时器
timerObj->start();
Expand Down
5 changes: 4 additions & 1 deletion src/controller/helpermanager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -37,8 +37,11 @@
void dbusSend(const QStringList &deleteList, const QStringList &addList);
//判断返回md文件符合优先选择。
QStringList handlePriority(const QStringList &list);
// filetime 有记录但 search 无数据时,清除 filetime 以触发重建
void reconcileIncompleteIndex(QMap<QString, QString> &mapFile,
const QMap<QString, QString> &mapNow);

private slots:

Check warning on line 44 in src/controller/helpermanager.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
//文件列表发生改变信号槽
void onFilelistChange(QStringList deleteList, QStringList addList, QStringList addTime);
void webLoadFinish(bool ok);
Expand Down
21 changes: 20 additions & 1 deletion src/controller/search_db.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -908,6 +908,25 @@
qCDebug(app) << "insertFilesTimeEntry done";
}

void SearchDb::insertFileTimeEntry(const QString &mdPath, const QString &modifyTime)
{
insertFilesTimeEntry(QStringList() << mdPath, QStringList() << modifyTime);
}

int SearchDb::searchEntryCount(const QString &appName, const QString &lang)
{
Q_ASSERT(p_->db.isOpen());
QSqlQuery query(p_->db);
query.prepare("SELECT COUNT(*) FROM search WHERE appName=? AND lang=?");

Check warning on line 920 in src/controller/search_db.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function query.prepare() is not used.
query.bindValue(0, appName);
query.bindValue(1, lang);
if (query.exec() && query.next()) {
return query.value(0).toInt();
}
qCWarning(app) << "searchEntryCount failed:" << query.lastError().text();
return 0;
}

/**
* @brief SearchDb::deleteFilesTimeEntry
* @param listMdPath 删除文件路径列表
Expand Down
5 changes: 4 additions & 1 deletion src/controller/search_db.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -52,10 +52,13 @@ public slots:
//文件信息插入数据库 (先删除数据,再插入数据)
void insertFilesTimeEntry(const QStringList &listMdPath,
const QStringList &listDataTime);
void insertFileTimeEntry(const QString &mdPath, const QString &modifyTime);

//根据mdPath删除表数据
void deleteFilesTimeEntry(const QStringList &listMdPath);

int searchEntryCount(const QString &appName, const QString &lang);

//查找filetime表所有内容, key:md文件路径 value: md文件更新时间
QMap<QString, QString> selectAllFileTime();

Expand Down
Loading