Skip to content

fix: update search filter logic and visibility#595

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-search-package
Jul 7, 2025
Merged

fix: update search filter logic and visibility#595
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-search-package

Conversation

@wjyrich

@wjyrich wjyrich commented Jul 4, 2025

Copy link
Copy Markdown
Contributor
  1. Changed Desktop ID search visibility from private to public in model configuration
  2. Refactored search filter logic to simplify conditional check for package name search
  3. The Desktop ID search feature is now properly exposed as a public API
  4. Improved code structure by removing unnecessary nested condition for package search

fix: 更新搜索过滤逻辑和可见性

  1. 将模型配置中的Desktop ID搜索可见性从私有改为公开
  2. 重构了搜索过滤逻辑,简化了包名搜索的条件检查
  3. Desktop ID搜索功能现在作为公共API正确暴露
  4. 通过移除包搜索中不必要的嵌套条件改善了代码结构

Summary by Sourcery

Expose Desktop ID search publicly and simplify the search filter logic by moving the enable check into the matching predicate and eliminating unnecessary nesting.

Bug Fixes:

  • Expose Desktop ID search as a public API by updating its visibility in the model configuration.
  • Fix search filter logic to ensure Desktop ID matching respects the package search enable flag.

Enhancements:

  • Refactor search filter logic to inline the package search condition within the predicate and remove redundant nested checks.

@sourcery-ai

sourcery-ai Bot commented Jul 4, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR exposes the Desktop ID search as a public API by updating its visibility in the model configuration and refactors the search filter proxy logic to simplify package name filtering by inlining and removing redundant conditionals.

Entity relationship diagram for Desktop ID search API visibility

erDiagram
    SEARCHFILTERPROXYMODEL ||--o{ DESKTOP_ID_SEARCH : exposes
    DESKTOP_ID_SEARCH {
        visibility PUBLIC
    }
Loading

Class diagram for updated SearchFilterProxyModel search logic

classDiagram
    class SearchFilterProxyModel {
        - m_searchPackageEnabled: bool
        + calculateWeight(modelIndex: QModelIndex): int
    }
    SearchFilterProxyModel : calculateWeight() now always adds desktopId search to matchTypes
    SearchFilterProxyModel : desktopId search conditional simplified
Loading

File-Level Changes

Change Details Files
Expose Desktop ID search as public API
  • Changed Desktop ID search visibility from private to public in model configuration
  • Updated API interface to properly expose Desktop ID search feature
src/models/org.deepin.ds.launchpad.json
Simplify package name search logic
  • Removed wrapping if-block around package search and inlined the enabled check into the lambda
  • Eliminated unnecessary nested conditional to streamline match type evaluation
src/models/searchfilterproxymodel.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

@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.

Hey @wjyrich - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/models/searchfilterproxymodel.cpp:271` </location>
<code_context>

     // 包名搜索(仅在配置启用时生效)
-    if (m_searchPackageEnabled) {
-        matchTypes.push_back(qMakePair(QString("desktopId"), [&]() -> bool {
+    matchTypes.push_back(qMakePair(QString("desktopId"), [&]() -> bool {
+        if (m_searchPackageEnabled) 
             return desktopIdLower.contains(searchPatternLower);
         }));
</code_context>

<issue_to_address>
The lambda may return an undefined value if m_searchPackageEnabled is false.

Explicitly return false in the else branch to avoid undefined behavior and ensure the lambda always returns a boolean value.
</issue_to_address>

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.

Comment thread src/models/searchfilterproxymodel.cpp Outdated
1. Changed Desktop ID search visibility from private to public in model
configuration
2. Refactored search filter logic to simplify conditional check for
package name search
3. The Desktop ID search feature is now properly exposed as a public API
4. Improved code structure by removing unnecessary nested condition for
package search

fix: 更新搜索过滤逻辑和可见性

1. 将模型配置中的Desktop ID搜索可见性从私有改为公开
2. 重构了搜索过滤逻辑,简化了包名搜索的条件检查
3. Desktop ID搜索功能现在作为公共API正确暴露
4. 通过移除包搜索中不必要的嵌套条件改善了代码结构
@wjyrich wjyrich force-pushed the fix-search-package branch from 14d0106 to 2086850 Compare July 4, 2025 09:26
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. 代码可读性:

    • searchfilterproxymodel.cpp文件中,对matchTypes的添加操作进行了重构,将条件判断移到了lambda表达式中,这提高了代码的可读性。但是,如果m_searchPackageEnabled变量在后续代码中频繁使用,可以考虑将其提取为一个局部变量,以减少重复代码。
  2. 逻辑一致性:

    • 修改后的代码逻辑与原代码一致,没有改变原有的功能。但是,将条件判断移到lambda表达式中,可能会影响性能,因为每次调用calculateWeight方法时都会进行条件判断。如果m_searchPackageEnabled的值在调用之间不会改变,可以考虑将其作为lambda表达式的参数传递,以避免重复判断。
  3. 代码维护性:

    • 代码重构提高了代码的可读性和维护性。但是,如果m_searchPackageEnabled的值在调用之间可能会改变,那么这种重构可能会引入新的维护负担,因为每次调用calculateWeight方法时都需要进行条件判断。
  4. 安全性:

    • 代码中没有涉及到安全性问题,因为修改的只是配置项的可见性,没有涉及到数据操作或用户输入。
  5. 性能:

    • 代码重构可能会略微影响性能,因为每次调用calculateWeight方法时都需要进行条件判断。但是,这种影响通常很小,除非m_searchPackageEnabled的值在调用之间频繁改变。

综上所述,代码重构提高了代码的可读性和维护性,但是可能略微影响性能。如果m_searchPackageEnabled的值在调用之间可能会改变,那么可以考虑将条件判断移到lambda表达式的参数中,以避免重复判断。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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 commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot deepin-bot Bot merged commit fda5a9b into linuxdeepin:master Jul 7, 2025
9 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.

3 participants