Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Nov 11, 2025

Added Qt::MatchExactly flag to the match() function call to ensure proper duplicate detection
This prevents multiple instances of the same application from being added to the model
The previous implementation could incorrectly match partial desktop IDs, leading to duplicates

fix: 添加精确匹配标志以防止重复应用条目

在 match() 函数调用中添加了 Qt::MatchExactly 标志以确保正确的重复检测
这可以防止同一应用程序的多个实例被添加到模型中
之前的实现可能会错误地匹配部分桌面 ID,导致重复条目

PMS: BUG-339003 BUG-339005

Summary by Sourcery

Bug Fixes:

  • Add Qt::MatchExactly flag to the match() call to ensure proper duplicate detection of desktop IDs

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This pull request enhances the duplicate detection logic in the application model by updating the match() call to use an exact match flag and limit results, preventing partial desktop ID matches from causing duplicate entries.

Sequence diagram for exact duplicate detection on InterfacesAdded

sequenceDiagram
    participant ObjectManager
    participant AMAppItemModel
    ObjectManager->>AMAppItemModel: InterfacesAdded(objPath, interfacesAndProperties)
    AMAppItemModel->>AMAppItemModel: DUtil::unescapeFromObjectPath(objPath)
    AMAppItemModel->>AMAppItemModel: match(index, DesktopIdRole, desktopId, 1, MatchExactly)
    AMAppItemModel-->>ObjectManager: (if match found) return (do not add duplicate)
    AMAppItemModel->>AMAppItemModel: (if no match) proceed to add new app entry
Loading

Class diagram for updated duplicate detection in AMAppItemModel

classDiagram
    class AMAppItemModel {
        +QObject *parent
        +ObjectManager *m_manager
        +AMAppItemModel(QObject *parent)
        +match(QModelIndex, int role, QVariant value, int hits = 1, Qt::MatchFlag flag = Qt::MatchExactly)
    }
    AMAppItemModel --> ObjectManager
    AMAppItemModel : connect(m_manager, InterfacesAdded, lambda)
    AMAppItemModel : match(index(0, 0), AppItemModel_DesktopIdRole, desktopId, 1, Qt_MatchExactly)
Loading

File-Level Changes

Change Details Files
Use exact matching for duplicate app entries
  • Include Qt::MatchExactly flag in match() call
  • Set maximum matches to 1 to short-circuit on first hit
applets/dde-apps/amappitemmodel.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider adding Qt::MatchRecursive to the match flags so the search spans the entire model rather than just the starting row.
  • Replace the literal ‘1’ hits parameter with a named constant or helper method to clarify its role as a match count limit.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding Qt::MatchRecursive to the match flags so the search spans the entire model rather than just the starting row.
- Replace the literal ‘1’ hits parameter with a named constant or helper method to clarify its role as a match count limit.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

mhduiy
mhduiy previously approved these changes Nov 11, 2025
Added Qt::MatchExactly flag to the match() function call to ensure
proper duplicate detection
This prevents multiple instances of the same application from being
added to the model
The previous implementation could incorrectly match partial desktop IDs,
leading to duplicates

fix: 添加精确匹配标志以防止重复应用条目

在 match() 函数调用中添加了 Qt::MatchExactly 标志以确保正确的重复检测
这可以防止同一应用程序的多个实例被添加到模型中
之前的实现可能会错误地匹配部分桌面 ID,导致重复条目

PMS: BUG-339005
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个git diff进行代码审查:

  1. 语法逻辑改进:
  • 代码语法正确,没有明显的语法错误
  • 修改后的代码增加了两个参数:1Qt::MatchExactly,这使得匹配更加精确
  1. 代码质量改进:
  • 修改后的代码更加严谨。通过添加 Qt::MatchExactly 标志,确保了精确匹配而不是模糊匹配
  • 限制搜索结果数量为1个(通过参数 1),这样可以提高效率,因为我们只需要知道是否存在匹配项
  • 改进后的代码在逻辑上更加清晰,明确表达了"只需要一个精确匹配"的意图
  1. 代码性能改进:
  • 通过限制匹配结果数量为1个,可以提前终止搜索,提高性能
  • 使用精确匹配(Qt::MatchExactly)比默认的模糊匹配更高效
  • 这两个改动都能减少不必要的搜索操作
  1. 代码安全改进:
  • 没有明显的安全隐患
  • 精确匹配可以避免可能的误匹配情况
  • 建议在调用 match() 之前,可以添加对 desktopId 的有效性检查,例如检查是否为空字符串

总结:
这是一个很好的改进,使得代码更加健壮和高效。主要改进点是:

  1. 使用精确匹配替代默认的模糊匹配
  2. 限制搜索结果数量为1个
  3. 保持了原有的错误处理逻辑

建议:

  1. 可以考虑在函数开始处添加对 desktopId 的有效性检查
  2. 如果这段代码会被频繁调用,可以考虑将 desktopId 的提取逻辑封装成一个单独的函数,以减少代码重复

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, wjyrich

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

@wjyrich wjyrich merged commit bc37147 into linuxdeepin:master Nov 11, 2025
10 of 11 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.

4 participants