Skip to content

Conversation

Jack251970
Copy link
Member

Do not query again when setting private field of QueryText

From #3350, we use TextChanged event to invoke Query, which can cause duplicated call of Query if we use OnPropertyChange(nameof(QueryText)).

In this PR, we use

// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
// So we need to ignore it so that we will not call Query again
_ignoredQueryText = _queryText;

to resolve that.

Fix #3497, #3498.

@Jack251970 Jack251970 added the Dev branch only An issue or fix for the Dev branch build label May 2, 2025
@Jack251970 Jack251970 self-assigned this May 2, 2025
@prlabeler prlabeler bot added the bug Something isn't working label May 2, 2025
@Jack251970 Jack251970 requested review from Copilot and jjw24 May 2, 2025 07:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to prevent duplicate Query calls when setting the QueryText property by introducing a new field (_ignoredQueryText) to act as a flag.

  • Introduces _ignoredQueryText to bypass unnecessary Query calls.
  • Refactors the Query method to check _ignoredQueryText and return early when appropriate.
  • Replaces a direct assignment to SelectedResults with a call to BackToQueryResults for UI consistency.
Comments suppressed due to low confidence (1)

Flow.Launcher/ViewModel/MainViewModel.cs:1438

  • [nitpick] The comment regarding setting _ignoredQueryText is repeated in multiple parts of the code. Consider refactoring this logic into a helper method to ensure consistency and improve maintainability.
_queryText = queryBuilderTmp.ToString();

Copy link

github-actions bot commented May 2, 2025

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link

gitstream-cm bot commented May 2, 2025

🥷 Code experts: onesounds

Jack251970, onesounds have most 👩‍💻 activity in the files.
Jack251970 has most 🧠 knowledge in the files.

See details

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
MAY 130 additions & 67 deletions
APR 35 additions & 28 deletions
MAR 695 additions & 628 deletions 293 additions & 201 deletions
FEB 63 additions & 21 deletions 23 additions & 25 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions

Knowledge based on git-blame:
Jack251970: 34%

To learn more about /:\ gitStream - Visit our Docs

Copy link

gitstream-cm bot commented May 2, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented May 2, 2025

📝 Walkthrough

Walkthrough

The changes introduce a mechanism in the MainViewModel to prevent redundant query executions when the query text is programmatically updated, particularly when returning from the context menu to the main query results. This is achieved by tracking an ignored query text value and suppressing query execution if the text matches this value. Adjustments are also made to ensure the selected results view is properly restored to the query results when hiding the UI or navigating back from the context menu.

Changes

File(s) Change Summary
Flow.Launcher/ViewModel/MainViewModel.cs Introduced _ignoredQueryText field; updated logic in SelectedResults, Query, and BuildQueryAsync to suppress redundant queries; replaced direct assignment in Hide with BackToQueryResults() for restoring results view.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainViewModel
    participant UI

    User->>UI: Interact with context menu
    UI->>MainViewModel: Set SelectedResults to Results
    MainViewModel->>MainViewModel: Set _ignoredQueryText to _queryText
    MainViewModel->>MainViewModel: Raise OnPropertyChanged(QueryText)
    MainViewModel->>MainViewModel: Query method checks _ignoredQueryText
    alt _ignoredQueryText matches QueryText
        MainViewModel->>MainViewModel: Clear _ignoredQueryText and skip query
    else _ignoredQueryText does not match
        MainViewModel->>MainViewModel: Clear _ignoredQueryText and execute query
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Restore result list selection to the top result when returning from context menu (#3497)

Poem

A hop from menu back to list,
No more queries will persist—
The rabbit’s code is sharp and bright,
Preventing loops both day and night.
With every jump, results appear,
No extra hops—just what you cheer!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8bb96d7 and 247272c.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (6)
Flow.Launcher/ViewModel/MainViewModel.cs (6)

37-37: Good addition of the private field for query tracking.

This field is necessary for tracking query text changes that should not trigger a new query execution. It's properly initialized as null.


734-737: Elegant solution to prevent redundant query execution.

When returning from context menu to query results, setting _ignoredQueryText to match the current query text before raising OnPropertyChanged ensures that the subsequent query execution triggered by the property change is ignored. This effectively prevents duplicate queries while maintaining the expected UI behavior.


1083-1095: Well-implemented early exit mechanism to prevent duplicate queries.

This addition to the Query method implements the core logic for preventing redundant queries. The code correctly:

  1. Checks if the ignored query text is set
  2. Compares it with the current query text
  3. Clears the ignored text regardless of the outcome
  4. Returns early only when the texts match

The code also includes helpful comments explaining the purpose of this mechanism.


1435-1443: Proper handling of query suppression after shortcut expansion.

When built-in shortcuts are expanded, the code sets _ignoredQueryText before triggering the property change notification. This prevents redundant query execution while still updating the UI to show the expanded text, maintaining a responsive user experience.


1624-1624: Good refactoring to use the dedicated method.

Replacing the conditional assignment with a call to BackToQueryResults() improves code readability and maintainability by centralizing the logic for returning to query results. This ensures consistent behavior across different parts of the application.


1191-1191: Consistent use of the navigation method.

The navigation back to query results now uses the reusable method App.API.BackToQueryResults() instead of directly manipulating the results view. This maintains consistency with the pattern established elsewhere in the code.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Jack251970 Jack251970 added this to the 1.20.0 milestone May 2, 2025
@jjw24 jjw24 removed the bug Something isn't working label May 3, 2025
@jjw24 jjw24 merged commit a2a8c50 into dev May 3, 2025
19 of 21 checks passed
@jjw24 jjw24 deleted the do_not_query_when_back_from_context_menu branch May 3, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev branch only An issue or fix for the Dev branch build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev branch- return to result list from context menu jump back to top result

2 participants