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 6163f6b
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 @@ -4,7 +4,7 @@ use std::sync::Arc;
use super::notifier::{SearchNotifier, SearchResultChanged, SearchResultReceiverRunner};
use crate::entities::{SearchFilterPB, SearchResultNotificationPB, SearchResultPB};
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 +63,42 @@ impl SearchManager {
self.handlers.get(&search_type)
}

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

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 +121,9 @@ impl SearchManager {
return;
},
};
let private_views = self.folder_manager.get_view_ids_should_be_filtered(folder);
tracing::warn!("Private views: {:?}", private_views);

let parent_view_ids = self.folder_manager.get_view_ids_should_be_filtered(folder);
let private_views = self.get_view_ids_should_be_filtered(parent_view_ids).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 6163f6b

Please sign in to comment.