Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: gen filter task

appflowy4d8f101a4257
diff --git a/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs b/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs
index c22c154600..cd40beba4c 100644
--- a/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/filter/filter_service.rs
@@ -3,28 +3,26 @@ use crate::services::block_manager::GridBlockManager;
use crate::services::tasks::Task;
use flowy_error::FlowyResult;
+use crate::services::grid_editor_task::GridServiceTaskScheduler;
use flowy_sync::client_grid::GridRevisionPad;
use std::sync::Arc;
use tokio::sync::RwLock;
pub(crate) struct GridFilterService {
- #[allow(dead_code)]
- scheduler: GridTaskSchedulerRwLock,
- #[allow(dead_code)]
+ scheduler: Arc<dyn GridServiceTaskScheduler>,
grid_pad: Arc<RwLock<GridRevisionPad>>,
- #[allow(dead_code)]
block_manager: Arc<GridBlockManager>,
}
impl GridFilterService {
- pub fn new(
+ pub fn new<S: GridServiceTaskScheduler>(
grid_pad: Arc<RwLock<GridRevisionPad>>,
block_manager: Arc<GridBlockManager>,
- scheduler: GridTaskSchedulerRwLock,
+ scheduler: S,
) -> Self {
Self {
grid_pad,
block_manager,
- scheduler,
+ scheduler: Arc::new(scheduler),
}
}
@@ -33,6 +31,8 @@ impl GridFilterService {
}
pub async fn notify_changed(&self) {
+ let task_id = self.scheduler.gen_task_id().await;
+
//
// let grid_pad = self.grid_pad.read().await;
// match grid_pad.get_filters(None) {
diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
index 97e36566b4..6675505120 100644
--- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
@@ -475,7 +475,10 @@ impl GridRevisionEditor {
.await?;
if is_filter_changed {
- self.filter_service.notify_changed().await;
+ let filter_service = self.filter_service.clone();
+ tokio::spawn(async move {
+ filter_service.notify_changed().await;
+ });
}
Ok(())
}
diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor_task.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor_task.rs
index 965cc0839e..c48ed2f370 100644
--- a/frontend/rust-lib/flowy-grid/src/services/grid_editor_task.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor_task.rs
@@ -1,9 +1,15 @@
+use crate::manager::GridTaskSchedulerRwLock;
use crate::services::grid_editor::GridRevisionEditor;
-use crate::services::tasks::{GridTaskHandler, Task, TaskContent, TaskHandlerId};
+use crate::services::tasks::{GridTaskHandler, Task, TaskContent, TaskHandlerId, TaskId};
use flowy_error::FlowyError;
-
+use futures::future::BoxFuture;
use lib_infra::future::BoxResultFuture;
+pub trait GridServiceTaskScheduler: Send + Sync + 'static {
+ fn gen_task_id(&self) -> BoxFuture<TaskId>;
+ fn register_task(&self, task: Task) -> BoxFuture<()>;
+}
+
impl GridTaskHandler for GridRevisionEditor {
fn handler_id(&self) -> &TaskHandlerId {
&self.grid_id
@@ -13,9 +19,23 @@ impl GridTaskHandler for GridRevisionEditor {
Box::pin(async move {
match &task.content {
TaskContent::Snapshot { .. } => {}
- TaskContent::Filter => self.filter_service.process_task(task).await?,
+ TaskContent::Filter { .. } => self.filter_service.process_task(task).await?,
}
Ok(())
})
}
}
+
+impl GridServiceTaskScheduler for GridTaskSchedulerRwLock {
+ fn gen_task_id(&self) -> BoxFuture<TaskId> {
+ let this = self.clone();
+ Box::pin(async move { this.read().await.next_task_id() })
+ }
+
+ fn register_task(&self, task: Task) -> BoxFuture<()> {
+ let this = self.clone();
+ Box::pin(async move {
+ this.write().await.register_task(task);
+ })
+ }
+}
diff --git a/frontend/rust-lib/flowy-grid/src/services/tasks/queue.rs b/frontend/rust-lib/flowy-grid/src/services/tasks/queue.rs
index 2c86d6606c..bccf2e9f89 100644
--- a/frontend/rust-lib/flowy-grid/src/services/tasks/queue.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/tasks/queue.rs
@@ -22,7 +22,7 @@ impl GridTaskQueue {
pub(crate) fn push(&mut self, task: &Task) {
let task_type = match task.content {
TaskContent::Snapshot { .. } => TaskType::Snapshot,
- TaskContent::Filter => TaskType::Filter,
+ TaskContent::Filter { .. } => TaskType::Filter,
};
let pending_task = PendingTask {
ty: task_type,
diff --git a/frontend/rust-lib/flowy-grid/src/services/tasks/scheduler.rs b/frontend/rust-lib/flowy-grid/src/services/tasks/scheduler.rs
index f4fb460eeb..7c05b0781b 100644
--- a/frontend/rust-lib/flowy-grid/src/services/tasks/scheduler.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/tasks/scheduler.rs
@@ -3,6 +3,7 @@ use crate::services::tasks::runner::GridTaskRunner;
use crate::services::tasks::store::GridTaskStore;
use crate::services::tasks::task::Task;
+use crate::services::tasks::TaskId;
use flowy_error::{FlowyError, FlowyResult};
use lib_infra::future::BoxResultFuture;
use std::collections::HashMap;
@@ -81,6 +82,10 @@ impl GridTaskScheduler {
self.notify();
}
+ pub fn next_task_id(&self) -> TaskId {
+ self.store.next_task_id()
+ }
+
pub fn notify(&self) {
let _ = self.notifier.send(());
}
diff --git a/frontend/rust-lib/flowy-grid/src/services/tasks/store.rs b/frontend/rust-lib/flowy-grid/src/services/tasks/store.rs
index 7f2fc8d695..549f0788ad 100644
--- a/frontend/rust-lib/flowy-grid/src/services/tasks/store.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/tasks/store.rs
@@ -24,7 +24,7 @@ impl GridTaskStore {
pub fn remove_task(&mut self, task_id: &TaskId) -> Option<Task> {
self.tasks.remove(task_id)
}
- #[allow(dead_code)]
+
pub fn next_task_id(&self) -> TaskId {
let _ = self.task_id_counter.fetch_add(1, SeqCst);
self.task_id_counter.load(SeqCst)
diff --git a/frontend/rust-lib/flowy-grid/src/services/tasks/task.rs b/frontend/rust-lib/flowy-grid/src/services/tasks/task.rs
index 00a6b158cc..0a337ec9c3 100644
--- a/frontend/rust-lib/flowy-grid/src/services/tasks/task.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/tasks/task.rs
@@ -44,16 +44,18 @@ impl Ord for PendingTask {
(TaskType::Snapshot, TaskType::Snapshot) => Ordering::Equal,
(TaskType::Snapshot, _) => Ordering::Greater,
(_, TaskType::Snapshot) => Ordering::Less,
- (TaskType::Filter, TaskType::Filter) => self.id.cmp(&other.id),
+ (TaskType::Filter, TaskType::Filter) => self.id.cmp(&other.id).reverse(),
}
}
}
-pub type ContentId = String;
+pub struct SnapshotTaskContext {}
+
+pub struct FilterTaskContext {}
pub enum TaskContent {
- Snapshot { content_id: ContentId },
- Filter,
+ Snapshot { context: SnapshotTaskContext },
+ Filter { context: FilterTaskContext },
}
pub struct Task {