Skip to content

refactor: update recent search D-Bus integration#330

Merged
Johnson-zs merged 1 commit into
linuxdeepin:semantic-searchfrom
Johnson-zs:semantic-search
Jun 26, 2026
Merged

refactor: update recent search D-Bus integration#330
Johnson-zs merged 1 commit into
linuxdeepin:semantic-searchfrom
Johnson-zs:semantic-search

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor
  1. Changed D-Bus service name to use the common FileManager daemon
    service
  2. Modified the D-Bus call to use QDBusPendingReply
    instead of handling raw JSON
  3. Simplified the data parsing by using QDBusArgument direct conversion
    to QVariantMap
  4. Fixed code indentation in filterByKeyword method parameters
  5. Removed unnecessary JSON parsing logic since D-Bus now returns
    structured data directly

The changes improve the reliability and performance of recent items
retrieval by:

  1. Using the correct standard D-Bus service name
  2. Eliminating the JSON serialization/deserialization overhead
  3. Making the code more maintainable with direct D-Bus type conversion
  4. Following better D-Bus integration practices

Influence:

  1. Verify recent items are still correctly retrieved and displayed
  2. Test search functionality with different keywords
  3. Check filterByKeyword method works as expected
  4. Ensure there are no D-Bus related errors in logs
  5. Test with various recent file scenarios (empty list, single item,
    multiple items)

refactor: 更新最近搜索的 D-Bus 集成

  1. 将 D-Bus 服务名称改为使用通用的文件管理器守护进程服务
  2. 修改 D-Bus 调用改用 QDBusPendingReply 而非处理原始 JSON
  3. 通过直接使用 QDBusArgument 转换到 QVariantMap 简化了数据解析
  4. 修复了 filterByKeyword 方法参数中的代码缩进
  5. 移除了不必要的 JSON 解析逻辑,因为 D-Bus 现在直接返回结构化数据

这些改进通过以下方式提升了最近项检索的可靠性和性能:

  1. 使用正确的标准 D-Bus 服务名称
  2. 消除了 JSON 序列化/反序列化的开销
  3. 通过直接的 D-Bus 类型转换使代码更易维护
  4. 遵循更好的 D-Bus 集成实践

Influence:

  1. 验证最近项目是否正确检索和显示
  2. 使用不同关键词测试搜索功能
  3. 检查 filterByKeyword 方法是否按预期工作
  4. 确保日志中没有 D-Bus 相关错误
  5. 测试各种最近文件场景(空列表、单个项目、多个项目)

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1. Changed D-Bus service name to use the common FileManager daemon
service
2. Modified the D-Bus call to use QDBusPendingReply<QVariantList>
instead of handling raw JSON
3. Simplified the data parsing by using QDBusArgument direct conversion
to QVariantMap
4. Fixed code indentation in filterByKeyword method parameters
5. Removed unnecessary JSON parsing logic since D-Bus now returns
structured data directly

The changes improve the reliability and performance of recent items
retrieval by:
1. Using the correct standard D-Bus service name
2. Eliminating the JSON serialization/deserialization overhead
3. Making the code more maintainable with direct D-Bus type conversion
4. Following better D-Bus integration practices

Influence:
1. Verify recent items are still correctly retrieved and displayed
2. Test search functionality with different keywords
3. Check filterByKeyword method works as expected
4. Ensure there are no D-Bus related errors in logs
5. Test with various recent file scenarios (empty list, single item,
multiple items)

refactor: 更新最近搜索的 D-Bus 集成

1. 将 D-Bus 服务名称改为使用通用的文件管理器守护进程服务
2. 修改 D-Bus 调用改用 QDBusPendingReply<QVariantList> 而非处理原始 JSON
3. 通过直接使用 QDBusArgument 转换到 QVariantMap 简化了数据解析
4. 修复了 filterByKeyword 方法参数中的代码缩进
5. 移除了不必要的 JSON 解析逻辑,因为 D-Bus 现在直接返回结构化数据

这些改进通过以下方式提升了最近项检索的可靠性和性能:
1. 使用正确的标准 D-Bus 服务名称
2. 消除了 JSON 序列化/反序列化的开销
3. 通过直接的 D-Bus 类型转换使代码更易维护
4. 遵循更好的 D-Bus 集成实践

Influence:
1. 验证最近项目是否正确检索和显示
2. 使用不同关键词测试搜索功能
3. 检查 filterByKeyword 方法是否按预期工作
4. 确保日志中没有 D-Bus 相关错误
5. 测试各种最近文件场景(空列表、单个项目、多个项目)
@Johnson-zs

Copy link
Copy Markdown
Contributor Author

/retest

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修正了DBus服务名及返回值解析逻辑,解决了类型不匹配问题,但缺少对DBus参数解包的异常防御
逻辑基本正确但因未校验QDBusArgument有效性扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

修复了DBus服务名错误和返回值类型不匹配问题,将JSON字符串解析重构为QDBusArgument解包
潜在问题:在fetchRecentItems中,直接调用v.value<QDBusArgument>()未检查转换是否成功,若服务端返回的数据结构发生变异,可能导致默认构造的QDBusArgument在执行>>操作时触发未定义行为或异常
建议:在执行dbusArg >> map前增加对dbusArg.currentType()的检查,确保其处于有效且预期的MapType状态

  • 2.代码质量(良好)✓

移除了冗余的JSON解析中间层,代码更加精简,同时修正了filterByKeyword函数参数的对齐格式
潜在问题:无明显问题
建议:可考虑为fetchRecentItems增加对topLevelList大小的合理上限检查,防止极端情况下的内存耗尽

  • 3.代码性能(高效)✓

消除了原代码中QStringQByteArray再反序列化为QJsonDocument的额外开销,直接通过DBus底层数据结构解包,降低了CPU和内存占用
潜在问题:无明显问题
建议:保持当前实现方式

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅涉及本地可信DBus服务的通信与数据解析,未引入命令注入、路径遍历等安全风险

  • 建议:确保调用方在使用item.path进行文件系统操作时,进行必要的路径规范化与权限校验

■ 【改进建议代码示例】

// 修复后的 fetchRecentItems 函数关键逻辑
constexpr auto kDBusService = "org.deepin.Filemanager.Daemon";
constexpr auto kDBusPath = "/org/deepin/Filemanager/Daemon/RecentManager";
constexpr auto kDBusInterface = "org.deepin.Filemanager.Daemon.RecentManager";
constexpr auto kDBusMethod = "GetItemsInfo";

QList<RecentItem> RecentSearchStrategy::fetchRecentItems()
{
    QList<RecentItem> items;
    // ... 前置 DBus 连接检查逻辑 ...
    
    QDBusPendingReply<QVariantList> reply = iface.call(QString::fromLatin1(kDBusMethod));
    if (!reply.isValid()) {
        qWarning() << "RecentManager GetItemsInfo failed:" << reply.error().message();
        return items;
    }
    
    const QVariantList &topLevelList = reply.value();
    for (const auto &v : topLevelList) {
        if (!v.canConvert<QDBusArgument>()) {
            qWarning() << "RecentManager: Invalid DBus argument type in list";
            continue;
        }
        
        QDBusArgument dbusArg = v.value<QDBusArgument>();
        if (dbusArg.currentType() != QDBusArgument::MapType) {
            qWarning() << "RecentManager: DBus argument is not a map type";
            continue;
        }

        QVariantMap map;
        dbusArg >> map;
        if (!map.isEmpty()) {
            RecentItem item;
            item.href = map.value("Href").toString();
            item.path = map.value("Path").toString();
            item.modified = static_cast<qint64>(map.value("modified").toLongLong());
            if (!item.path.isEmpty() && item.modified > 0) {
                items.append(std::move(item));
            }
        }
    }
    return items;
}

@Johnson-zs Johnson-zs merged commit 8982d66 into linuxdeepin:semantic-search Jun 26, 2026
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants