Skip to content

Commit

Permalink
fix: find all view ids to be filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed Jul 10, 2024
1 parent 2605a84 commit cf9cf4a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
4 changes: 3 additions & 1 deletion frontend/rust-lib/flowy-search/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub(crate) async fn search_handler(
) -> Result<(), FlowyError> {
let query = data.into_inner();
let manager = upgrade_manager(manager)?;
manager.perform_search(query.search, query.filter, query.channel);
manager
.perform_search(query.search, query.filter, query.channel)
.await;

Ok(())
}
44 changes: 39 additions & 5 deletions frontend/rust-lib/flowy-search/src/services/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::sync::Arc;

use super::notifier::{SearchNotifier, SearchResultChanged, SearchResultReceiverRunner};
use crate::entities::{SearchFilterPB, SearchResultNotificationPB, SearchResultPB};
use collab_folder::Folder;
use flowy_error::FlowyResult;
use flowy_folder::manager::FolderManager;
use flowy_folder::{entities::ViewPB, manager::FolderManager};
use lib_dispatch::prelude::af_spawn;
use lib_infra::async_trait::async_trait;
use tokio::sync::broadcast;
Expand Down Expand Up @@ -63,7 +64,42 @@ impl SearchManager {
self.handlers.get(&search_type)
}

pub fn perform_search(
async fn get_view_ids_should_be_filtered(&self, folder: &Folder) -> Vec<String> {
let mut filtered_ids: Vec<String> = self.folder_manager.get_view_ids_should_be_filtered(folder);

let view_futures = filtered_ids
.iter()
.map(|id| self.folder_manager.get_view_pb(id))
.collect::<Vec<_>>();

let view_results = futures::future::join_all(view_futures).await;

let views = view_results
.into_iter()
.filter(|view| view.is_ok())
.map(|view| view.unwrap())
.collect::<Vec<_>>();

for view in views {
let view_ids = self.get_view_ids_recursively(view);
filtered_ids.append(&mut view_ids.clone());
}

filtered_ids
}

fn get_view_ids_recursively(&self, view: ViewPB) -> Vec<String> {
let mut view_ids = vec![];
view_ids.push(view.id.clone());

for child in view.child_views.iter() {
view_ids.append(&mut self.get_view_ids_recursively(child.clone()));
}

view_ids
}

pub async fn perform_search(
&self,
query: String,
filter: Option<SearchFilterPB>,
Expand All @@ -86,9 +122,8 @@ impl SearchManager {
return;
},
};
let private_views = self.folder_manager.get_view_ids_should_be_filtered(folder);
tracing::warn!("Private views: {:?}", private_views);

let private_views = self.get_view_ids_should_be_filtered(folder).await;
let max: usize = self.handlers.len();
let handlers = self.handlers.clone();
for (_, handler) in handlers {
Expand All @@ -100,7 +135,6 @@ impl SearchManager {

af_spawn(async move {
let res = handler.perform_search(q.clone(), f).await;

let items = res.unwrap_or_default();

// Filter out any items which ID exists in private_views
Expand Down

0 comments on commit cf9cf4a

Please sign in to comment.