appflowy 3 роки тому
батько
коміт
ab63ce7bce

+ 6 - 20
frontend/rust-lib/flowy-grid/src/manager.rs

@@ -1,4 +1,5 @@
-use crate::services::grid_editor::GridMetaEditor;
+use crate::services::block::make_grid_block_meta_rev_manager;
+use crate::services::grid_meta_editor::GridMetaEditor;
 use crate::services::persistence::block_index::BlockIndexCache;
 use crate::services::persistence::kv::GridKVPersistence;
 use crate::services::persistence::GridDatabase;
@@ -7,7 +8,7 @@ use dashmap::DashMap;
 use flowy_database::ConnectionPool;
 use flowy_error::{FlowyError, FlowyResult};
 use flowy_grid_data_model::entities::{BuildGridContext, GridMeta};
-use flowy_revision::disk::{SQLiteGridBlockMetaRevisionPersistence, SQLiteGridRevisionPersistence};
+use flowy_revision::disk::SQLiteGridRevisionPersistence;
 use flowy_revision::{RevisionManager, RevisionPersistence, RevisionWebSocket};
 use flowy_sync::client_grid::{make_block_meta_delta, make_grid_delta};
 use flowy_sync::entities::revision::{RepeatedRevision, Revision};
@@ -35,12 +36,12 @@ impl GridManager {
     ) -> Self {
         let grid_editors = Arc::new(DashMap::new());
         let kv_persistence = Arc::new(GridKVPersistence::new(database.clone()));
-        let block_index_persistence = Arc::new(BlockIndexCache::new(database));
+        let block_index_cache = Arc::new(BlockIndexCache::new(database));
         Self {
             editor_map: grid_editors,
             grid_user,
+            block_index_cache,
             kv_persistence,
-            block_index_cache: block_index_persistence,
         }
     }
 
@@ -59,9 +60,7 @@ impl GridManager {
         block_id: T,
         revisions: RepeatedRevision,
     ) -> FlowyResult<()> {
-        let block_id = block_id.as_ref();
-        let db_pool = self.grid_user.db_pool()?;
-        let rev_manager = self.make_grid_block_meta_rev_manager(block_id, db_pool)?;
+        let rev_manager = make_grid_block_meta_rev_manager(&self.grid_user, block_id.as_ref())?;
         let _ = rev_manager.reset_object(revisions).await?;
         Ok(())
     }
@@ -134,18 +133,6 @@ impl GridManager {
         let rev_manager = RevisionManager::new(&user_id, grid_id, rev_persistence);
         Ok(rev_manager)
     }
-
-    fn make_grid_block_meta_rev_manager(
-        &self,
-        block_d: &str,
-        pool: Arc<ConnectionPool>,
-    ) -> FlowyResult<RevisionManager> {
-        let user_id = self.grid_user.user_id()?;
-        let disk_cache = Arc::new(SQLiteGridBlockMetaRevisionPersistence::new(&user_id, pool));
-        let rev_persistence = Arc::new(RevisionPersistence::new(&user_id, block_d, disk_cache));
-        let rev_manager = RevisionManager::new(&user_id, block_d, rev_persistence);
-        Ok(rev_manager)
-    }
 }
 
 pub async fn make_grid_view_data(
@@ -166,7 +153,6 @@ pub async fn make_grid_view_data(
     let repeated_revision: RepeatedRevision =
         Revision::initial_revision(user_id, view_id, grid_delta_data.clone()).into();
     let _ = grid_manager.create_grid(view_id, repeated_revision).await?;
-
     for block_meta_data in build_context.blocks_meta_data {
         let block_id = block_meta_data.block_id.clone();
 

+ 14 - 14
frontend/rust-lib/flowy-grid/src/services/block_meta_editor.rs → frontend/rust-lib/flowy-grid/src/services/block/block_meta_editor.rs

@@ -1,8 +1,8 @@
 use bytes::Bytes;
 use flowy_error::{FlowyError, FlowyResult};
-use flowy_grid_data_model::entities::{CellMeta, GridBlockMetaData, RowMeta, RowMetaChangeset, RowOrder};
+use flowy_grid_data_model::entities::{CellMeta, GridBlockMeta, RowMeta, RowMetaChangeset, RowOrder};
 use flowy_revision::{RevisionCloudService, RevisionCompactor, RevisionManager, RevisionObjectBuilder};
-use flowy_sync::client_grid::{GridBlockMetaChange, GridBlockMetaPad};
+use flowy_sync::client_grid::{GridBlockMetaDeltaChangeset, GridBlockMetaPad};
 use flowy_sync::entities::revision::Revision;
 use flowy_sync::util::make_delta_from_revisions;
 use lib_infra::future::FutureResult;
@@ -14,7 +14,7 @@ use tokio::sync::RwLock;
 pub struct GridBlockMetaEditor {
     user_id: String,
     pub block_id: String,
-    pad: Arc<RwLock<GridBlockMetaPad>>,
+    block_meta: Arc<RwLock<GridBlockMetaPad>>,
     rev_manager: Arc<RevisionManager>,
 }
 
@@ -29,20 +29,20 @@ impl GridBlockMetaEditor {
             token: token.to_owned(),
         });
         let block_meta_pad = rev_manager.load::<GridBlockMetaPadBuilder>(Some(cloud)).await?;
-        let pad = Arc::new(RwLock::new(block_meta_pad));
+        let block_meta = Arc::new(RwLock::new(block_meta_pad));
         let rev_manager = Arc::new(rev_manager);
         let user_id = user_id.to_owned();
         let block_id = block_id.to_owned();
         Ok(Self {
             user_id,
             block_id,
-            pad,
+            block_meta,
             rev_manager,
         })
     }
 
-    pub async fn duplicate_block_meta_data(&self, duplicated_block_id: &str) -> GridBlockMetaData {
-        self.pad.read().await.duplicate_data(duplicated_block_id).await
+    pub async fn duplicate_block_meta(&self, duplicated_block_id: &str) -> GridBlockMeta {
+        self.block_meta.read().await.duplicate_data(duplicated_block_id).await
     }
 
     /// return current number of rows and the inserted index. The inserted index will be None if the start_row_id is None
@@ -109,7 +109,7 @@ impl GridBlockMetaEditor {
     where
         T: AsRef<str> + ToOwned + ?Sized,
     {
-        let row_metas = self.pad.read().await.get_row_metas(row_ids)?;
+        let row_metas = self.block_meta.read().await.get_row_metas(row_ids)?;
         Ok(row_metas)
     }
 
@@ -118,7 +118,7 @@ impl GridBlockMetaEditor {
         field_id: &str,
         row_ids: Option<Vec<Cow<'_, String>>>,
     ) -> FlowyResult<Vec<CellMeta>> {
-        let cell_metas = self.pad.read().await.get_cell_metas(field_id, row_ids)?;
+        let cell_metas = self.block_meta.read().await.get_cell_metas(field_id, row_ids)?;
         Ok(cell_metas)
     }
 
@@ -132,7 +132,7 @@ impl GridBlockMetaEditor {
         T: AsRef<str> + ToOwned + ?Sized,
     {
         let row_orders = self
-            .pad
+            .block_meta
             .read()
             .await
             .get_row_metas(row_ids)?
@@ -144,9 +144,9 @@ impl GridBlockMetaEditor {
 
     async fn modify<F>(&self, f: F) -> FlowyResult<()>
     where
-        F: for<'a> FnOnce(&'a mut GridBlockMetaPad) -> FlowyResult<Option<GridBlockMetaChange>>,
+        F: for<'a> FnOnce(&'a mut GridBlockMetaPad) -> FlowyResult<Option<GridBlockMetaDeltaChangeset>>,
     {
-        let mut write_guard = self.pad.write().await;
+        let mut write_guard = self.block_meta.write().await;
         match f(&mut *write_guard)? {
             None => {}
             Some(change) => {
@@ -156,8 +156,8 @@ impl GridBlockMetaEditor {
         Ok(())
     }
 
-    async fn apply_change(&self, change: GridBlockMetaChange) -> FlowyResult<()> {
-        let GridBlockMetaChange { delta, md5 } = change;
+    async fn apply_change(&self, change: GridBlockMetaDeltaChangeset) -> FlowyResult<()> {
+        let GridBlockMetaDeltaChangeset { delta, md5 } = change;
         let user_id = self.user_id.clone();
         let (base_rev_id, rev_id) = self.rev_manager.next_rev_id_pair();
         let delta_data = delta.to_delta_bytes();

+ 25 - 20
frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs → frontend/rust-lib/flowy-grid/src/services/block/block_meta_manager.rs

@@ -1,13 +1,13 @@
 use crate::dart_notification::{send_dart_notification, GridNotification};
 use crate::manager::GridUser;
-use crate::services::block_meta_editor::GridBlockMetaEditor;
+use crate::services::block::GridBlockMetaEditor;
 use crate::services::persistence::block_index::BlockIndexCache;
 use crate::services::row::{group_row_orders, GridBlockSnapshot};
 use dashmap::DashMap;
 use flowy_error::FlowyResult;
 use flowy_grid_data_model::entities::{
-    CellChangeset, CellMeta, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset, IndexRowOrder, Row, RowMeta,
-    RowMetaChangeset, RowOrder, UpdatedRowOrder,
+    CellChangeset, CellMeta, GridBlockInfoChangeset, GridBlockMetaSnapshot, GridRowsChangeset, IndexRowOrder, Row,
+    RowMeta, RowMetaChangeset, RowOrder, UpdatedRowOrder,
 };
 use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
 use flowy_revision::{RevisionManager, RevisionPersistence};
@@ -16,19 +16,19 @@ use std::collections::HashMap;
 use std::sync::Arc;
 
 type BlockId = String;
-pub(crate) struct GridBlockManager {
+pub(crate) struct GridBlockMetaManager {
     grid_id: String,
     user: Arc<dyn GridUser>,
-    persistence: Arc<BlockIndexCache>,
+    block_index_cache: Arc<BlockIndexCache>,
     block_editor_map: DashMap<BlockId, Arc<GridBlockMetaEditor>>,
 }
 
-impl GridBlockManager {
+impl GridBlockMetaManager {
     pub(crate) async fn new(
         grid_id: &str,
         user: &Arc<dyn GridUser>,
-        blocks: Vec<GridBlockMeta>,
-        persistence: Arc<BlockIndexCache>,
+        blocks: Vec<GridBlockMetaSnapshot>,
+        block_index_cache: Arc<BlockIndexCache>,
     ) -> FlowyResult<Self> {
         let editor_map = make_block_meta_editor_map(user, blocks).await?;
         let user = user.clone();
@@ -37,7 +37,7 @@ impl GridBlockManager {
             grid_id,
             user,
             block_editor_map: editor_map,
-            persistence,
+            block_index_cache,
         };
         Ok(manager)
     }
@@ -57,7 +57,7 @@ impl GridBlockManager {
     }
 
     async fn get_editor_from_row_id(&self, row_id: &str) -> FlowyResult<Arc<GridBlockMetaEditor>> {
-        let block_id = self.persistence.get_block_id(row_id)?;
+        let block_id = self.block_index_cache.get_block_id(row_id)?;
         Ok(self.get_editor(&block_id).await?)
     }
 
@@ -67,7 +67,7 @@ impl GridBlockManager {
         row_meta: RowMeta,
         start_row_id: Option<String>,
     ) -> FlowyResult<i32> {
-        let _ = self.persistence.insert(&row_meta.block_id, &row_meta.id)?;
+        let _ = self.block_index_cache.insert(&row_meta.block_id, &row_meta.id)?;
         let editor = self.get_editor(&row_meta.block_id).await?;
 
         let mut index_row_order = IndexRowOrder::from(&row_meta);
@@ -83,21 +83,21 @@ impl GridBlockManager {
     pub(crate) async fn insert_row(
         &self,
         rows_by_block_id: HashMap<String, Vec<RowMeta>>,
-    ) -> FlowyResult<Vec<GridBlockMetaChangeset>> {
+    ) -> FlowyResult<Vec<GridBlockInfoChangeset>> {
         let mut changesets = vec![];
         for (block_id, row_metas) in rows_by_block_id {
             let mut inserted_row_orders = vec![];
             let editor = self.get_editor(&block_id).await?;
             let mut row_count = 0;
             for row in row_metas {
-                let _ = self.persistence.insert(&row.block_id, &row.id)?;
+                let _ = self.block_index_cache.insert(&row.block_id, &row.id)?;
                 let mut row_order = IndexRowOrder::from(&row);
                 let (count, index) = editor.create_row(row, None).await?;
                 row_count = count;
                 row_order.index = index;
                 inserted_row_orders.push(row_order);
             }
-            changesets.push(GridBlockMetaChangeset::from_row_count(&block_id, row_count));
+            changesets.push(GridBlockInfoChangeset::from_row_count(&block_id, row_count));
 
             let _ = self
                 .notify_did_update_block(GridRowsChangeset::insert(&block_id, inserted_row_orders))
@@ -128,7 +128,7 @@ impl GridBlockManager {
 
     pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
         let row_id = row_id.to_owned();
-        let block_id = self.persistence.get_block_id(&row_id)?;
+        let block_id = self.block_index_cache.get_block_id(&row_id)?;
         let editor = self.get_editor(&block_id).await?;
         match editor.get_row_order(&row_id).await? {
             None => {}
@@ -143,7 +143,7 @@ impl GridBlockManager {
         Ok(())
     }
 
-    pub(crate) async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<Vec<GridBlockMetaChangeset>> {
+    pub(crate) async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<Vec<GridBlockInfoChangeset>> {
         let mut changesets = vec![];
         for block_order in group_row_orders(row_orders) {
             let editor = self.get_editor(&block_order.block_id).await?;
@@ -153,7 +153,7 @@ impl GridBlockManager {
                 .map(|row_order| Cow::Owned(row_order.row_id))
                 .collect::<Vec<Cow<String>>>();
             let row_count = editor.delete_rows(row_ids).await?;
-            let changeset = GridBlockMetaChangeset::from_row_count(&block_order.block_id, row_count);
+            let changeset = GridBlockInfoChangeset::from_row_count(&block_order.block_id, row_count);
             changesets.push(changeset);
         }
 
@@ -255,7 +255,7 @@ impl GridBlockManager {
 
 async fn make_block_meta_editor_map(
     user: &Arc<dyn GridUser>,
-    blocks: Vec<GridBlockMeta>,
+    blocks: Vec<GridBlockMetaSnapshot>,
 ) -> FlowyResult<DashMap<String, Arc<GridBlockMetaEditor>>> {
     let editor_map = DashMap::new();
     for block in blocks {
@@ -269,11 +269,16 @@ async fn make_block_meta_editor_map(
 async fn make_block_meta_editor(user: &Arc<dyn GridUser>, block_id: &str) -> FlowyResult<GridBlockMetaEditor> {
     tracing::trace!("Open block:{} meta editor", block_id);
     let token = user.token()?;
+    let user_id = user.user_id()?;
+    let rev_manager = make_grid_block_meta_rev_manager(user, block_id)?;
+    GridBlockMetaEditor::new(&user_id, &token, block_id, rev_manager).await
+}
+
+pub fn make_grid_block_meta_rev_manager(user: &Arc<dyn GridUser>, block_id: &str) -> FlowyResult<RevisionManager> {
     let user_id = user.user_id()?;
     let pool = user.db_pool()?;
 
     let disk_cache = Arc::new(SQLiteGridBlockMetaRevisionPersistence::new(&user_id, pool));
     let rev_persistence = Arc::new(RevisionPersistence::new(&user_id, block_id, disk_cache));
-    let rev_manager = RevisionManager::new(&user_id, block_id, rev_persistence);
-    GridBlockMetaEditor::new(&user_id, &token, block_id, rev_manager).await
+    Ok(RevisionManager::new(&user_id, block_id, rev_persistence))
 }

+ 5 - 0
frontend/rust-lib/flowy-grid/src/services/block/mod.rs

@@ -0,0 +1,5 @@
+mod block_meta_editor;
+mod block_meta_manager;
+
+pub(crate) use block_meta_editor::*;
+pub(crate) use block_meta_manager::*;

+ 31 - 24
frontend/rust-lib/flowy-grid/src/services/grid_editor.rs → frontend/rust-lib/flowy-grid/src/services/grid_meta_editor.rs

@@ -1,7 +1,7 @@
 use crate::dart_notification::{send_dart_notification, GridNotification};
 use crate::entities::CellIdentifier;
 use crate::manager::GridUser;
-use crate::services::block_meta_manager::GridBlockManager;
+use crate::services::block::GridBlockMetaManager;
 use crate::services::field::{default_type_option_builder_from_type, type_option_builder_from_bytes, FieldBuilder};
 use crate::services::persistence::block_index::BlockIndexCache;
 use crate::services::row::*;
@@ -24,7 +24,7 @@ pub struct GridMetaEditor {
     user: Arc<dyn GridUser>,
     grid_pad: Arc<RwLock<GridMetaPad>>,
     rev_manager: Arc<RevisionManager>,
-    block_manager: Arc<GridBlockManager>,
+    block_meta_manager: Arc<GridBlockMetaManager>,
 }
 
 impl Drop for GridMetaEditor {
@@ -47,13 +47,13 @@ impl GridMetaEditor {
         let grid_pad = Arc::new(RwLock::new(grid_pad));
         let blocks = grid_pad.read().await.get_block_metas();
 
-        let block_meta_manager = Arc::new(GridBlockManager::new(grid_id, &user, blocks, persistence).await?);
+        let block_meta_manager = Arc::new(GridBlockMetaManager::new(grid_id, &user, blocks, persistence).await?);
         Ok(Arc::new(Self {
             grid_id: grid_id.to_owned(),
             user,
             grid_pad,
             rev_manager,
-            block_manager: block_meta_manager,
+            block_meta_manager,
         }))
     }
 
@@ -240,12 +240,12 @@ impl GridMetaEditor {
         Ok(field_metas)
     }
 
-    pub async fn create_block(&self, grid_block: GridBlockMeta) -> FlowyResult<()> {
+    pub async fn create_block(&self, grid_block: GridBlockMetaSnapshot) -> FlowyResult<()> {
         let _ = self.modify(|grid| Ok(grid.create_block_meta(grid_block)?)).await?;
         Ok(())
     }
 
-    pub async fn update_block(&self, changeset: GridBlockMetaChangeset) -> FlowyResult<()> {
+    pub async fn update_block(&self, changeset: GridBlockInfoChangeset) -> FlowyResult<()> {
         let _ = self.modify(|grid| Ok(grid.update_block_meta(changeset)?)).await?;
         Ok(())
     }
@@ -260,10 +260,13 @@ impl GridMetaEditor {
         let row_order = RowOrder::from(&row_meta);
 
         // insert the row
-        let row_count = self.block_manager.create_row(&block_id, row_meta, start_row_id).await?;
+        let row_count = self
+            .block_meta_manager
+            .create_row(&block_id, row_meta, start_row_id)
+            .await?;
 
         // update block row count
-        let changeset = GridBlockMetaChangeset::from_row_count(&block_id, row_count);
+        let changeset = GridBlockInfoChangeset::from_row_count(&block_id, row_count);
         let _ = self.update_block(changeset).await?;
         Ok(row_order)
     }
@@ -280,7 +283,7 @@ impl GridMetaEditor {
                 .or_insert_with(Vec::new)
                 .push(row_meta);
         }
-        let changesets = self.block_manager.insert_row(rows_by_block_id).await?;
+        let changesets = self.block_meta_manager.insert_row(rows_by_block_id).await?;
         for changeset in changesets {
             let _ = self.update_block(changeset).await?;
         }
@@ -289,7 +292,7 @@ impl GridMetaEditor {
 
     pub async fn update_row(&self, changeset: RowMetaChangeset) -> FlowyResult<()> {
         let field_metas = self.get_field_metas::<FieldOrder>(None).await?;
-        self.block_manager
+        self.block_meta_manager
             .update_row(changeset, |row_meta| make_row_from_row_meta(&field_metas, row_meta))
             .await
     }
@@ -312,7 +315,7 @@ impl GridMetaEditor {
     }
 
     pub async fn get_row(&self, row_id: &str) -> FlowyResult<Option<Row>> {
-        match self.block_manager.get_row_meta(row_id).await? {
+        match self.block_meta_manager.get_row_meta(row_id).await? {
             None => Ok(None),
             Some(row_meta) => {
                 let field_metas = self.get_field_metas::<FieldOrder>(None).await?;
@@ -324,7 +327,7 @@ impl GridMetaEditor {
         }
     }
     pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
-        let _ = self.block_manager.delete_row(row_id).await?;
+        let _ = self.block_meta_manager.delete_row(row_id).await?;
         Ok(())
     }
 
@@ -334,12 +337,12 @@ impl GridMetaEditor {
 
     pub async fn get_cell(&self, params: &CellIdentifier) -> Option<Cell> {
         let field_meta = self.get_field_meta(&params.field_id).await?;
-        let row_meta = self.block_manager.get_row_meta(&params.row_id).await.ok()??;
+        let row_meta = self.block_meta_manager.get_row_meta(&params.row_id).await.ok()??;
         make_cell(&params.field_id, &field_meta, &row_meta)
     }
 
     pub async fn get_cell_meta(&self, row_id: &str, field_id: &str) -> FlowyResult<Option<CellMeta>> {
-        let row_meta = self.block_manager.get_row_meta(row_id).await?;
+        let row_meta = self.block_meta_manager.get_row_meta(row_id).await?;
         match row_meta {
             None => Ok(None),
             Some(row_meta) => {
@@ -385,7 +388,7 @@ impl GridMetaEditor {
                     cell_content_changeset,
                 };
                 let _ = self
-                    .block_manager
+                    .block_meta_manager
                     .update_cell(cell_changeset, |row_meta| {
                         make_row_from_row_meta(&field_metas, row_meta)
                     })
@@ -400,13 +403,13 @@ impl GridMetaEditor {
         make_grid_blocks(block_ids, block_snapshots)
     }
 
-    pub async fn get_block_metas(&self) -> FlowyResult<Vec<GridBlockMeta>> {
+    pub async fn get_block_metas(&self) -> FlowyResult<Vec<GridBlockMetaSnapshot>> {
         let grid_blocks = self.grid_pad.read().await.get_block_metas();
         Ok(grid_blocks)
     }
 
     pub async fn delete_rows(&self, row_orders: Vec<RowOrder>) -> FlowyResult<()> {
-        let changesets = self.block_manager.delete_rows(row_orders).await?;
+        let changesets = self.block_meta_manager.delete_rows(row_orders).await?;
         for changeset in changesets {
             let _ = self.update_block(changeset).await?;
         }
@@ -418,7 +421,7 @@ impl GridMetaEditor {
         let field_orders = pad_read_guard.get_field_orders();
         let mut block_orders = vec![];
         for block_order in pad_read_guard.get_block_metas() {
-            let row_orders = self.block_manager.get_row_orders(&block_order.block_id).await?;
+            let row_orders = self.block_meta_manager.get_row_orders(&block_order.block_id).await?;
             let block_order = GridBlockOrder {
                 block_id: block_order.block_id,
                 row_orders,
@@ -445,7 +448,7 @@ impl GridMetaEditor {
                 .collect::<Vec<String>>(),
             Some(block_ids) => block_ids,
         };
-        let snapshots = self.block_manager.make_block_snapshots(block_ids).await?;
+        let snapshots = self.block_meta_manager.make_block_snapshots(block_ids).await?;
         Ok(snapshots)
     }
 
@@ -479,7 +482,10 @@ impl GridMetaEditor {
     }
 
     pub async fn move_row(&self, row_id: &str, from: i32, to: i32) -> FlowyResult<()> {
-        let _ = self.block_manager.move_row(row_id, from as usize, to as usize).await?;
+        let _ = self
+            .block_meta_manager
+            .move_row(row_id, from as usize, to as usize)
+            .await?;
         Ok(())
     }
 
@@ -495,13 +501,14 @@ impl GridMetaEditor {
         let mut blocks_meta_data = vec![];
         if original_blocks.len() == duplicated_blocks.len() {
             for (index, original_block_meta) in original_blocks.iter().enumerate() {
-                let grid_block_meta_editor = self.block_manager.get_editor(&original_block_meta.block_id).await?;
+                let grid_block_meta_editor = self
+                    .block_meta_manager
+                    .get_editor(&original_block_meta.block_id)
+                    .await?;
                 let duplicated_block_id = &duplicated_blocks[index].block_id;
 
                 tracing::trace!("Duplicate block:{} meta data", duplicated_block_id);
-                let duplicated_block_meta_data = grid_block_meta_editor
-                    .duplicate_block_meta_data(duplicated_block_id)
-                    .await;
+                let duplicated_block_meta_data = grid_block_meta_editor.duplicate_block_meta(duplicated_block_id).await;
                 blocks_meta_data.push(duplicated_block_meta_data);
             }
         } else {

+ 2 - 3
frontend/rust-lib/flowy-grid/src/services/mod.rs

@@ -1,8 +1,7 @@
 mod util;
 
-pub mod block_meta_editor;
-mod block_meta_manager;
+pub mod block;
 pub mod field;
-pub mod grid_editor;
+pub mod grid_meta_editor;
 pub mod persistence;
 pub mod row;

+ 4 - 4
frontend/rust-lib/flowy-grid/tests/grid/grid_test.rs

@@ -7,7 +7,7 @@ use flowy_grid::services::field::{
 };
 use flowy_grid::services::row::{decode_cell_data_from_type_option_cell_data, CreateRowMetaBuilder};
 use flowy_grid_data_model::entities::{
-    CellChangeset, FieldChangesetParams, FieldType, GridBlockMeta, GridBlockMetaChangeset, RowMetaChangeset,
+    CellChangeset, FieldChangesetParams, FieldType, GridBlockInfoChangeset, GridBlockMetaSnapshot, RowMetaChangeset,
     TypeOptionDataEntry,
 };
 
@@ -123,7 +123,7 @@ async fn grid_delete_field() {
 
 #[tokio::test]
 async fn grid_create_block() {
-    let grid_block = GridBlockMeta::new();
+    let grid_block = GridBlockMetaSnapshot::new();
     let scripts = vec![
         AssertBlockCount(1),
         CreateBlock { block: grid_block },
@@ -134,9 +134,9 @@ async fn grid_create_block() {
 
 #[tokio::test]
 async fn grid_update_block() {
-    let grid_block = GridBlockMeta::new();
+    let grid_block = GridBlockMetaSnapshot::new();
     let mut cloned_grid_block = grid_block.clone();
-    let changeset = GridBlockMetaChangeset {
+    let changeset = GridBlockInfoChangeset {
         block_id: grid_block.block_id.clone(),
         start_row_index: Some(2),
         row_count: Some(10),

+ 8 - 7
frontend/rust-lib/flowy-grid/tests/grid/script.rs

@@ -1,10 +1,11 @@
 use bytes::Bytes;
 use flowy_grid::services::field::*;
-use flowy_grid::services::grid_editor::{GridMetaEditor, GridPadBuilder};
+use flowy_grid::services::grid_meta_editor::{GridMetaEditor, GridPadBuilder};
 use flowy_grid::services::row::CreateRowMetaPayload;
 use flowy_grid_data_model::entities::{
-    BuildGridContext, CellChangeset, Field, FieldChangesetParams, FieldMeta, FieldOrder, FieldType, GridBlockMeta,
-    GridBlockMetaChangeset, InsertFieldParams, RowMeta, RowMetaChangeset, RowOrder, TypeOptionDataEntry,
+    BuildGridContext, CellChangeset, Field, FieldChangesetParams, FieldMeta, FieldOrder, FieldType,
+    GridBlockInfoChangeset, GridBlockMetaSnapshot, InsertFieldParams, RowMeta, RowMetaChangeset, RowOrder,
+    TypeOptionDataEntry,
 };
 use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
 use flowy_sync::client_grid::GridBuilder;
@@ -32,10 +33,10 @@ pub enum EditorScript {
         field_meta: FieldMeta,
     },
     CreateBlock {
-        block: GridBlockMeta,
+        block: GridBlockMetaSnapshot,
     },
     UpdateBlock {
-        changeset: GridBlockMetaChangeset,
+        changeset: GridBlockInfoChangeset,
     },
     AssertBlockCount(usize),
     AssertBlock {
@@ -45,7 +46,7 @@ pub enum EditorScript {
     },
     AssertBlockEqual {
         block_index: usize,
-        block: GridBlockMeta,
+        block: GridBlockMetaSnapshot,
     },
     CreateEmptyRow,
     CreateRow {
@@ -74,7 +75,7 @@ pub struct GridEditorTest {
     pub grid_id: String,
     pub editor: Arc<GridMetaEditor>,
     pub field_metas: Vec<FieldMeta>,
-    pub grid_blocks: Vec<GridBlockMeta>,
+    pub grid_blocks: Vec<GridBlockMetaSnapshot>,
     pub row_metas: Vec<Arc<RowMeta>>,
     pub field_count: usize,
 

+ 10 - 10
shared-lib/flowy-grid-data-model/src/entities/meta.rs

@@ -28,17 +28,17 @@ pub fn gen_field_id() -> String {
 pub struct GridMeta {
     pub grid_id: String,
     pub fields: Vec<FieldMeta>,
-    pub blocks: Vec<GridBlockMeta>,
+    pub blocks: Vec<GridBlockMetaSnapshot>,
 }
 
 #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
-pub struct GridBlockMeta {
+pub struct GridBlockMetaSnapshot {
     pub block_id: String,
     pub start_row_index: i32,
     pub row_count: i32,
 }
 
-impl GridBlockMeta {
+impl GridBlockMetaSnapshot {
     pub fn len(&self) -> i32 {
         self.row_count
     }
@@ -48,22 +48,22 @@ impl GridBlockMeta {
     }
 }
 
-impl GridBlockMeta {
+impl GridBlockMetaSnapshot {
     pub fn new() -> Self {
-        GridBlockMeta {
+        GridBlockMetaSnapshot {
             block_id: gen_block_id(),
             ..Default::default()
         }
     }
 }
 
-pub struct GridBlockMetaChangeset {
+pub struct GridBlockInfoChangeset {
     pub block_id: String,
     pub start_row_index: Option<i32>,
     pub row_count: Option<i32>,
 }
 
-impl GridBlockMetaChangeset {
+impl GridBlockInfoChangeset {
     pub fn from_row_count(block_id: &str, row_count: i32) -> Self {
         Self {
             block_id: block_id.to_string(),
@@ -74,7 +74,7 @@ impl GridBlockMetaChangeset {
 }
 
 #[derive(Debug, Clone, Default, Serialize, Deserialize)]
-pub struct GridBlockMetaData {
+pub struct GridBlockMeta {
     pub block_id: String,
     pub rows: Vec<RowMeta>,
 }
@@ -206,8 +206,8 @@ impl CellMeta {
 #[derive(Clone, Default, Deserialize, Serialize)]
 pub struct BuildGridContext {
     pub field_metas: Vec<FieldMeta>,
-    pub blocks: Vec<GridBlockMeta>,
-    pub blocks_meta_data: Vec<GridBlockMetaData>,
+    pub blocks: Vec<GridBlockMetaSnapshot>,
+    pub blocks_meta_data: Vec<GridBlockMeta>,
 }
 
 impl BuildGridContext {

+ 7 - 9
shared-lib/flowy-sync/src/client_grid/grid_block_meta_pad.rs

@@ -1,9 +1,7 @@
 use crate::entities::revision::{md5, RepeatedRevision, Revision};
 use crate::errors::{CollaborateError, CollaborateResult};
 use crate::util::{cal_diff, make_delta_from_revisions};
-use flowy_grid_data_model::entities::{
-    gen_block_id, gen_row_id, CellMeta, GridBlockMetaData, RowMeta, RowMetaChangeset,
-};
+use flowy_grid_data_model::entities::{gen_block_id, gen_row_id, CellMeta, GridBlockMeta, RowMeta, RowMetaChangeset};
 use lib_ot::core::{OperationTransformable, PlainTextAttributes, PlainTextDelta, PlainTextDeltaBuilder};
 use serde::{Deserialize, Serialize};
 use std::borrow::Cow;
@@ -24,7 +22,7 @@ pub struct GridBlockMetaPad {
 }
 
 impl GridBlockMetaPad {
-    pub async fn duplicate_data(&self, duplicated_block_id: &str) -> GridBlockMetaData {
+    pub async fn duplicate_data(&self, duplicated_block_id: &str) -> GridBlockMeta {
         let duplicated_rows = self
             .rows
             .iter()
@@ -35,7 +33,7 @@ impl GridBlockMetaPad {
                 duplicated_row
             })
             .collect::<Vec<RowMeta>>();
-        GridBlockMetaData {
+        GridBlockMeta {
             block_id: duplicated_block_id.to_string(),
             rows: duplicated_rows,
         }
@@ -43,7 +41,7 @@ impl GridBlockMetaPad {
 
     pub fn from_delta(delta: GridBlockMetaDelta) -> CollaborateResult<Self> {
         let s = delta.to_str()?;
-        let meta_data: GridBlockMetaData = serde_json::from_str(&s).map_err(|e| {
+        let meta_data: GridBlockMeta = serde_json::from_str(&s).map_err(|e| {
             let msg = format!("Deserialize delta to block meta failed: {}", e);
             tracing::error!("{}", s);
             CollaborateError::internal().context(msg)
@@ -241,12 +239,12 @@ pub struct GridBlockMetaChange {
     pub md5: String,
 }
 
-pub fn make_block_meta_delta(grid_block_meta_data: &GridBlockMetaData) -> GridBlockMetaDelta {
+pub fn make_block_meta_delta(grid_block_meta_data: &GridBlockMeta) -> GridBlockMetaDelta {
     let json = serde_json::to_string(&grid_block_meta_data).unwrap();
     PlainTextDeltaBuilder::new().insert(&json).build()
 }
 
-pub fn make_block_meta_revisions(user_id: &str, grid_block_meta_data: &GridBlockMetaData) -> RepeatedRevision {
+pub fn make_block_meta_revisions(user_id: &str, grid_block_meta_data: &GridBlockMeta) -> RepeatedRevision {
     let delta = make_block_meta_delta(grid_block_meta_data);
     let bytes = delta.to_delta_bytes();
     let revision = Revision::initial_revision(user_id, &grid_block_meta_data.block_id, bytes);
@@ -255,7 +253,7 @@ pub fn make_block_meta_revisions(user_id: &str, grid_block_meta_data: &GridBlock
 
 impl std::default::Default for GridBlockMetaPad {
     fn default() -> Self {
-        let block_meta_data = GridBlockMetaData {
+        let block_meta_data = GridBlockMeta {
             block_id: gen_block_id(),
             rows: vec![],
         };

+ 5 - 5
shared-lib/flowy-sync/src/client_grid/grid_builder.rs

@@ -1,5 +1,5 @@
 use crate::errors::{CollaborateError, CollaborateResult};
-use flowy_grid_data_model::entities::{BuildGridContext, FieldMeta, GridBlockMeta, GridBlockMetaData, RowMeta};
+use flowy_grid_data_model::entities::{BuildGridContext, FieldMeta, GridBlockMeta, GridBlockMetaSnapshot, RowMeta};
 
 pub struct GridBuilder {
     build_context: BuildGridContext,
@@ -9,8 +9,8 @@ impl std::default::Default for GridBuilder {
     fn default() -> Self {
         let mut build_context = BuildGridContext::new();
 
-        let block_meta = GridBlockMeta::new();
-        let block_meta_data = GridBlockMetaData {
+        let block_meta = GridBlockMetaSnapshot::new();
+        let block_meta_data = GridBlockMeta {
             block_id: block_meta.block_id.clone(),
             rows: vec![],
         };
@@ -59,7 +59,7 @@ fn check_rows(fields: &[FieldMeta], rows: &[RowMeta]) -> CollaborateResult<()> {
 mod tests {
 
     use crate::client_grid::{make_block_meta_delta, make_grid_delta, GridBuilder};
-    use flowy_grid_data_model::entities::{FieldMeta, FieldType, GridBlockMetaData, GridMeta};
+    use flowy_grid_data_model::entities::{FieldMeta, FieldType, GridBlockMeta, GridMeta};
 
     #[test]
     fn create_default_grid_test() {
@@ -82,6 +82,6 @@ mod tests {
         let _: GridMeta = serde_json::from_str(&grid_meta_delta.to_str().unwrap()).unwrap();
 
         let grid_block_meta_delta = make_block_meta_delta(build_context.blocks_meta_data.first().unwrap());
-        let _: GridBlockMetaData = serde_json::from_str(&grid_block_meta_delta.to_str().unwrap()).unwrap();
+        let _: GridBlockMeta = serde_json::from_str(&grid_block_meta_delta.to_str().unwrap()).unwrap();
     }
 }

+ 8 - 8
shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs

@@ -3,8 +3,8 @@ use crate::errors::{internal_error, CollaborateError, CollaborateResult};
 use crate::util::{cal_diff, make_delta_from_revisions};
 use bytes::Bytes;
 use flowy_grid_data_model::entities::{
-    gen_block_id, gen_grid_id, FieldChangesetParams, FieldMeta, FieldOrder, FieldType, GridBlockMeta,
-    GridBlockMetaChangeset, GridMeta,
+    gen_block_id, gen_grid_id, FieldChangesetParams, FieldMeta, FieldOrder, FieldType, GridBlockInfoChangeset,
+    GridBlockMetaSnapshot, GridMeta,
 };
 use lib_infra::util::move_vec_element;
 use lib_ot::core::{OperationTransformable, PlainTextAttributes, PlainTextDelta, PlainTextDeltaBuilder};
@@ -24,7 +24,7 @@ pub trait JsonDeserializer {
 }
 
 impl GridMetaPad {
-    pub async fn duplicate_grid_meta(&self) -> (Vec<FieldMeta>, Vec<GridBlockMeta>) {
+    pub async fn duplicate_grid_meta(&self) -> (Vec<FieldMeta>, Vec<GridBlockMetaSnapshot>) {
         let fields = self
             .grid_meta
             .fields
@@ -41,7 +41,7 @@ impl GridMetaPad {
                 duplicated_block.block_id = gen_block_id();
                 duplicated_block
             })
-            .collect::<Vec<GridBlockMeta>>();
+            .collect::<Vec<GridBlockMetaSnapshot>>();
 
         (fields, blocks)
     }
@@ -283,7 +283,7 @@ impl GridMetaPad {
         }
     }
 
-    pub fn create_block_meta(&mut self, block: GridBlockMeta) -> CollaborateResult<Option<GridChangeset>> {
+    pub fn create_block_meta(&mut self, block: GridBlockMetaSnapshot) -> CollaborateResult<Option<GridChangeset>> {
         self.modify_grid(|grid_meta| {
             if grid_meta.blocks.iter().any(|b| b.block_id == block.block_id) {
                 tracing::warn!("Duplicate grid block");
@@ -306,11 +306,11 @@ impl GridMetaPad {
         })
     }
 
-    pub fn get_block_metas(&self) -> Vec<GridBlockMeta> {
+    pub fn get_block_metas(&self) -> Vec<GridBlockMetaSnapshot> {
         self.grid_meta.blocks.clone()
     }
 
-    pub fn update_block_meta(&mut self, changeset: GridBlockMetaChangeset) -> CollaborateResult<Option<GridChangeset>> {
+    pub fn update_block_meta(&mut self, changeset: GridBlockInfoChangeset) -> CollaborateResult<Option<GridChangeset>> {
         let block_id = changeset.block_id.clone();
         self.modify_block(&block_id, |block| {
             let mut is_changed = None;
@@ -368,7 +368,7 @@ impl GridMetaPad {
 
     pub fn modify_block<F>(&mut self, block_id: &str, f: F) -> CollaborateResult<Option<GridChangeset>>
     where
-        F: FnOnce(&mut GridBlockMeta) -> CollaborateResult<Option<()>>,
+        F: FnOnce(&mut GridBlockMetaSnapshot) -> CollaborateResult<Option<()>>,
     {
         self.modify_grid(
             |grid_meta| match grid_meta.blocks.iter().position(|block| block.block_id == block_id) {