mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: search workspace sync indexing (#5437)
* fix: search workspace sync indexing * chore: update collab rev temporarily * feat: revert comparison and implement index check * chore: fixes after merg * chore: enable search * chore: disable ai test --------- Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
@ -14,7 +14,7 @@ collab-plugins = { workspace = true }
|
||||
collab-integrate = { workspace = true }
|
||||
flowy-folder-pub = { workspace = true }
|
||||
flowy-search-pub = { workspace = true }
|
||||
|
||||
flowy-sqlite = { workspace = true }
|
||||
flowy-derive.workspace = true
|
||||
flowy-notification = { workspace = true }
|
||||
parking_lot.workspace = true
|
||||
@ -35,6 +35,7 @@ strum_macros = "0.21"
|
||||
protobuf.workspace = true
|
||||
uuid.workspace = true
|
||||
tokio-stream = { workspace = true, features = ["sync"] }
|
||||
serde = { workspace = true, features = ["derive"]}
|
||||
serde_json.workspace = true
|
||||
validator = "0.16.0"
|
||||
async-trait.workspace = true
|
||||
|
@ -232,3 +232,8 @@ pub struct UserFolderPB {
|
||||
#[pb(index = 2)]
|
||||
pub workspace_id: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
|
||||
pub struct IndexedWorkspaceIds {
|
||||
pub workspace_ids: Vec<String>,
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_folder_pub::cloud::{gen_view_id, FolderCloudService};
|
||||
use flowy_folder_pub::folder_builder::ParentChildViews;
|
||||
use flowy_search_pub::entities::FolderIndexManager;
|
||||
use flowy_sqlite::kv::StorePreferences;
|
||||
use parking_lot::RwLock;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::ops::Deref;
|
||||
@ -50,15 +51,17 @@ pub struct FolderManager {
|
||||
pub(crate) operation_handlers: FolderOperationHandlers,
|
||||
pub cloud_service: Arc<dyn FolderCloudService>,
|
||||
pub(crate) folder_indexer: Arc<dyn FolderIndexManager>,
|
||||
pub(crate) store_preferences: Arc<StorePreferences>,
|
||||
}
|
||||
|
||||
impl FolderManager {
|
||||
pub async fn new(
|
||||
pub fn new(
|
||||
user: Arc<dyn FolderUser>,
|
||||
collab_builder: Arc<AppFlowyCollabBuilder>,
|
||||
operation_handlers: FolderOperationHandlers,
|
||||
cloud_service: Arc<dyn FolderCloudService>,
|
||||
folder_indexer: Arc<dyn FolderIndexManager>,
|
||||
store_preferences: Arc<StorePreferences>,
|
||||
) -> FlowyResult<Self> {
|
||||
let mutex_folder = Arc::new(MutexFolder::default());
|
||||
let manager = Self {
|
||||
@ -68,6 +71,7 @@ impl FolderManager {
|
||||
operation_handlers,
|
||||
cloud_service,
|
||||
folder_indexer,
|
||||
store_preferences,
|
||||
};
|
||||
|
||||
Ok(manager)
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::entities::IndexedWorkspaceIds;
|
||||
use crate::manager::{FolderInitDataSource, FolderManager};
|
||||
use crate::manager_observer::*;
|
||||
use crate::user_default::DefaultFolderBuilder;
|
||||
@ -10,6 +11,8 @@ use std::sync::{Arc, Weak};
|
||||
use tokio::task::spawn_blocking;
|
||||
use tracing::{event, info, Level};
|
||||
|
||||
pub const INDEXED_WORKSPACE_KEY: &str = "indexed-workspace-ids";
|
||||
|
||||
impl FolderManager {
|
||||
/// Called immediately after the application launched if the user already sign in/sign up.
|
||||
#[tracing::instrument(level = "info", skip(self, initial_data), err)]
|
||||
@ -118,18 +121,7 @@ impl FolderManager {
|
||||
self
|
||||
.folder_indexer
|
||||
.set_index_content_receiver(index_content_rx, workspace_id.clone());
|
||||
|
||||
// Index all views in the folder if needed
|
||||
if !self.folder_indexer.is_indexed() {
|
||||
let views = folder.views.get_all_views();
|
||||
let folder_indexer = self.folder_indexer.clone();
|
||||
|
||||
// We spawn a blocking task to index all views in the folder
|
||||
let wid = workspace_id.clone();
|
||||
spawn_blocking(move || {
|
||||
folder_indexer.index_all_views(views, wid);
|
||||
});
|
||||
}
|
||||
self.handle_index_folder(workspace_id.clone(), &folder);
|
||||
|
||||
*self.mutex_folder.write() = Some(folder);
|
||||
|
||||
@ -156,6 +148,7 @@ impl FolderManager {
|
||||
&weak_mutex_folder,
|
||||
Arc::downgrade(&self.user),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -192,4 +185,41 @@ impl FolderManager {
|
||||
folder_data,
|
||||
))
|
||||
}
|
||||
|
||||
fn handle_index_folder(&self, workspace_id: String, folder: &Folder) {
|
||||
let index_all;
|
||||
if self.folder_indexer.is_indexed() {
|
||||
// If indexes already exist, we check if the workspace was
|
||||
// previously indexed, if it wasn't we index all
|
||||
let indexed_ids = self
|
||||
.store_preferences
|
||||
.get_object::<IndexedWorkspaceIds>(INDEXED_WORKSPACE_KEY);
|
||||
if let Some(indexed_ids) = indexed_ids {
|
||||
index_all = !indexed_ids.workspace_ids.contains(&workspace_id.clone());
|
||||
if !index_all {
|
||||
let mut workspace_ids = indexed_ids.workspace_ids.clone();
|
||||
workspace_ids.push(workspace_id.clone());
|
||||
let _ = self
|
||||
.store_preferences
|
||||
.set_object(INDEXED_WORKSPACE_KEY, IndexedWorkspaceIds { workspace_ids });
|
||||
}
|
||||
} else {
|
||||
index_all = true;
|
||||
}
|
||||
} else {
|
||||
// If there exists no indexes, we index all views in workspace
|
||||
index_all = true;
|
||||
}
|
||||
|
||||
if index_all {
|
||||
let views = folder.views.get_all_views();
|
||||
let folder_indexer = self.folder_indexer.clone();
|
||||
let wid = workspace_id.clone();
|
||||
|
||||
// We spawn a blocking task to index all views in the folder
|
||||
spawn_blocking(move || {
|
||||
folder_indexer.index_all_views(views, wid);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user