Skip to content

fix: search panel issues #8093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

asjqkkkk
Copy link
Collaborator

@asjqkkkk asjqkkkk commented Jun 30, 2025

  • fix: sometimes cannot get the preview of search result
  • fix: click the ask AI button from the search panel twice, then second time doesn’t work

Feature Preview


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Copy link
Contributor

sourcery-ai bot commented Jun 30, 2025

Reviewer's Guide

This PR refactors the view‐fetching logic in CommandPaletteBloc to robustly handle failures by using a fold-based result, logging errors, and retrying the fetch until it succeeds, and ensures this behavior is enabled on initialization.

Sequence diagram for robust view fetching with retry in CommandPaletteBloc

sequenceDiagram
    participant CommandPaletteBloc
    participant ViewBackendService
    participant Log
    actor Timer as Retry Timer

    CommandPaletteBloc->>ViewBackendService: getAllViews()
    alt Success
        ViewBackendService-->>CommandPaletteBloc: Result (views)
        CommandPaletteBloc->>CommandPaletteBloc: add(updateCachedViews)
    else Failure
        ViewBackendService-->>CommandPaletteBloc: Error
        CommandPaletteBloc->>Log: error(message)
        alt refreshUntilSuccess is true
            CommandPaletteBloc->>Timer: Future.delayed(3s)
            Timer-->>CommandPaletteBloc: (after 3s)
            CommandPaletteBloc->>ViewBackendService: getAllViews() (retry)
        end
    end
Loading

File-Level Changes

Change Details Files
Enhanced view-fetching with retry-until-success
  • Updated _refreshCachedViews signature to accept a refreshUntilSuccess flag
  • Replaced toNullable null check with result.fold(success, error)
  • On error, log failure and schedule a recursive retry after a 3-second delay when flag is true
frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
Added logging support and enabled forced refresh on init
  • Imported the logging package
  • Changed constructor to call _refreshCachedViews(refreshUntilSuccess: true)
frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart

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
Contributor

@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 @asjqkkkk - 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> `frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart:100` </location>
<code_context>
+        'command palette bloc gets all views failed: $e${refreshUntilSuccess ? ', retrying...' : ''}',
+      );
+      if (refreshUntilSuccess) {
+        unawaited(
+          Future.delayed(
+            const Duration(seconds: 3),
+            () => _refreshCachedViews(refreshUntilSuccess: true),
+          ),
+        );
</code_context>

<issue_to_address>
Potential for unbounded retries if getAllViews keeps failing.

Add a maximum retry limit or implement exponential backoff to prevent resource exhaustion and excessive logging.

Suggested implementation:

```
    if (isClosed) return;
    final result = await ViewBackendService.getAllViews();
    result.fold((v) {
      if (isClosed) return;
      add(CommandPaletteEvent.updateCachedViews(views: v.items));
    }, (e) {
      Log.error(
        'command palette bloc gets all views failed: $e${refreshUntilSuccess ? ', retrying...' : ''}',
      );
      if (refreshUntilSuccess) {
        // Retry logic with max retries and exponential backoff
        const int maxRetries = 5;
        final int currentRetry = retryCount ?? 0;
        if (currentRetry < maxRetries) {
          final int delaySeconds = 3 * (1 << currentRetry); // Exponential backoff: 3, 6, 12, 24, 48
          unawaited(
            Future.delayed(
              Duration(seconds: delaySeconds),
              () => _refreshCachedViews(
                refreshUntilSuccess: true,
                retryCount: currentRetry + 1,
              ),
            ),
          );
        } else {
          Log.error(
            'command palette bloc gets all views failed after $maxRetries retries. Giving up.',
          );
        }
      }
    }

  }

  Future<void> _refreshCachedViews({bool refreshUntilSuccess = false, int? retryCount}) async {
    /// Sometimes non-existent views appear in the search results
    /// and the icon data for the search results is empty
    /// Fetching all views can temporarily resolve these issues

```

- You must update all calls to `_refreshCachedViews` to include the new `retryCount` parameter where appropriate, or ensure it defaults to `null`/`0` for initial calls.
- If you want to make the retry/backoff logic configurable, consider moving `maxRetries` and the base delay to class-level constants.
</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 on lines +100 to +103
unawaited(
Future.delayed(
const Duration(seconds: 3),
() => _refreshCachedViews(refreshUntilSuccess: true),
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Potential for unbounded retries if getAllViews keeps failing.

Add a maximum retry limit or implement exponential backoff to prevent resource exhaustion and excessive logging.

Suggested implementation:

    if (isClosed) return;
    final result = await ViewBackendService.getAllViews();
    result.fold((v) {
      if (isClosed) return;
      add(CommandPaletteEvent.updateCachedViews(views: v.items));
    }, (e) {
      Log.error(
        'command palette bloc gets all views failed: $e${refreshUntilSuccess ? ', retrying...' : ''}',
      );
      if (refreshUntilSuccess) {
        // Retry logic with max retries and exponential backoff
        const int maxRetries = 5;
        final int currentRetry = retryCount ?? 0;
        if (currentRetry < maxRetries) {
          final int delaySeconds = 3 * (1 << currentRetry); // Exponential backoff: 3, 6, 12, 24, 48
          unawaited(
            Future.delayed(
              Duration(seconds: delaySeconds),
              () => _refreshCachedViews(
                refreshUntilSuccess: true,
                retryCount: currentRetry + 1,
              ),
            ),
          );
        } else {
          Log.error(
            'command palette bloc gets all views failed after $maxRetries retries. Giving up.',
          );
        }
      }
    }

  }

  Future<void> _refreshCachedViews({bool refreshUntilSuccess = false, int? retryCount}) async {
    /// Sometimes non-existent views appear in the search results
    /// and the icon data for the search results is empty
    /// Fetching all views can temporarily resolve these issues

  • You must update all calls to _refreshCachedViews to include the new retryCount parameter where appropriate, or ensure it defaults to null/0 for initial calls.
  • If you want to make the retry/backoff logic configurable, consider moving maxRetries and the base delay to class-level constants.

@asjqkkkk asjqkkkk changed the title fix: get all views in search panel until success fix: search panel issues Jun 30, 2025
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.

1 participant