diff --git a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart index 859b80d172..4e900f91d2 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart @@ -1,3 +1,5 @@ +import 'package:flutter/foundation.dart'; + import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/shared/feature_flags.dart'; import 'package:appflowy/user/application/user_listener.dart'; @@ -10,7 +12,6 @@ import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; import 'package:appflowy_result/appflowy_result.dart'; import 'package:collection/collection.dart'; import 'package:easy_localization/easy_localization.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:protobuf/protobuf.dart'; @@ -55,23 +56,22 @@ class UserWorkspaceBloc extends Bloc { await _userService.openWorkspace(currentWorkspace.workspaceId); } - WorkspaceMemberPB? currentWorkspaceMember; - final workspaceMemberResult = - await _userService.getWorkspaceMember(); - currentWorkspaceMember = workspaceMemberResult.fold( - (s) => s, - (e) => null, - ); - emit( state.copyWith( currentWorkspace: currentWorkspace, workspaces: workspaces, isCollabWorkspaceOn: isCollabWorkspaceOn, - currentWorkspaceMember: currentWorkspaceMember, actionResult: null, ), ); + + /// We wait with fetching the workspace member as it may take some time, + /// to avoid blocking the UI from rendering (the sidebar). + final workspaceMemberResult = + await _userService.getWorkspaceMember(); + final workspaceMember = workspaceMemberResult.toNullable(); + + emit(state.copyWith(currentWorkspaceMember: workspaceMember)); }, fetchWorkspaces: () async { final result = await _fetchWorkspaces(); @@ -208,14 +208,6 @@ class UserWorkspaceBloc extends Bloc { (e) => state.currentWorkspace, ); - WorkspaceMemberPB? currentWorkspaceMember; - final workspaceMemberResult = - await _userService.getWorkspaceMember(); - currentWorkspaceMember = workspaceMemberResult.fold( - (s) => s, - (e) => null, - ); - result ..onSuccess((s) { Log.info( @@ -229,7 +221,6 @@ class UserWorkspaceBloc extends Bloc { emit( state.copyWith( currentWorkspace: currentWorkspace, - currentWorkspaceMember: currentWorkspaceMember, actionResult: UserWorkspaceActionResult( actionType: UserWorkspaceActionType.open, isLoading: false, @@ -237,6 +228,14 @@ class UserWorkspaceBloc extends Bloc { ), ), ); + + /// We wait with fetching the workspace member as it may take some time, + /// to avoid blocking the UI from rendering (the sidebar). + final workspaceMemberResult = + await _userService.getWorkspaceMember(); + final workspaceMember = workspaceMemberResult.toNullable(); + + emit(state.copyWith(currentWorkspaceMember: workspaceMember)); }, renameWorkspace: (workspaceId, name) async { final result = diff --git a/frontend/rust-lib/flowy-search/src/document/handler.rs b/frontend/rust-lib/flowy-search/src/document/handler.rs index ffdafb8cc7..3cb499a5ce 100644 --- a/frontend/rust-lib/flowy-search/src/document/handler.rs +++ b/frontend/rust-lib/flowy-search/src/document/handler.rs @@ -1,4 +1,5 @@ use std::sync::Arc; +use tracing::{trace, warn}; use flowy_error::FlowyResult; use flowy_folder::{manager::FolderManager, ViewLayout}; @@ -52,6 +53,7 @@ impl SearchHandler for DocumentSearchHandler { .cloud_service .document_search(&workspace_id, query) .await?; + trace!("[Search] remote search results: {:?}", results); // Grab all views from folder cache // Notice that `get_all_view_pb` returns Views that don't include trashed and private views @@ -86,9 +88,12 @@ impl SearchHandler for DocumentSearchHandler { workspace_id: result.workspace_id, preview: result.preview, }); + } else { + warn!("No view found for search result: {:?}", result); } } + trace!("[Search] showing results: {:?}", search_results); Ok(search_results) } diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/search.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/search.rs index c0bf6e2dea..552a94068a 100644 --- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/search.rs +++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/search.rs @@ -11,7 +11,8 @@ pub(crate) struct AFCloudSearchCloudServiceImpl { // The limit of what the score should be for results, used to // filter out irrelevant results. -const SCORE_LIMIT: f64 = 0.8; +// https://community.openai.com/t/rule-of-thumb-cosine-similarity-thresholds/693670/5 +const SCORE_LIMIT: f64 = 0.3; const DEFAULT_PREVIEW: u32 = 80; #[async_trait] @@ -32,7 +33,7 @@ where // Filter out irrelevant results let result = result .into_iter() - .filter(|r| r.score < SCORE_LIMIT) + .filter(|r| r.score > SCORE_LIMIT) .collect(); Ok(result)