chore: fix deserialize GridBlockMetaPad error

This commit is contained in:
appflowy
2022-04-10 10:31:55 +08:00
parent a755d52371
commit 420b8ca05d
22 changed files with 605 additions and 231 deletions

View File

@ -6,7 +6,7 @@ const OBSERVABLE_CATEGORY: &str = "Grid";
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
DidUpdateBlock = 20,
DidUpdateGridBlock = 20,
DidUpdateRow = 30,
DidUpdateCell = 31,
DidUpdateGrid = 40,

View File

@ -110,6 +110,7 @@ impl GridManager {
}
}
#[tracing::instrument(level = "trace", skip(self, pool), err)]
async fn make_grid_editor(
&self,
grid_id: &str,
@ -175,11 +176,11 @@ pub async fn make_grid_view_data(
grid_manager: Arc<GridManager>,
build_context: BuildGridContext,
) -> FlowyResult<Bytes> {
let block_id = build_context.block_metas.block_id.clone();
let block_id = build_context.block_meta.block_id.clone();
let grid_meta = GridMeta {
grid_id: view_id.to_string(),
fields: build_context.field_metas,
blocks: vec![build_context.block_metas],
blocks: vec![build_context.block_meta],
};
// Create grid

View File

@ -27,7 +27,7 @@
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
DidUpdateBlock = 20,
DidUpdateGridBlock = 20,
DidUpdateRow = 30,
DidUpdateCell = 31,
DidUpdateGrid = 40,
@ -43,7 +43,7 @@ impl ::protobuf::ProtobufEnum for GridNotification {
match value {
0 => ::std::option::Option::Some(GridNotification::Unknown),
11 => ::std::option::Option::Some(GridNotification::DidCreateBlock),
20 => ::std::option::Option::Some(GridNotification::DidUpdateBlock),
20 => ::std::option::Option::Some(GridNotification::DidUpdateGridBlock),
30 => ::std::option::Option::Some(GridNotification::DidUpdateRow),
31 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
40 => ::std::option::Option::Some(GridNotification::DidUpdateGrid),
@ -56,7 +56,7 @@ impl ::protobuf::ProtobufEnum for GridNotification {
static values: &'static [GridNotification] = &[
GridNotification::Unknown,
GridNotification::DidCreateBlock,
GridNotification::DidUpdateBlock,
GridNotification::DidUpdateGridBlock,
GridNotification::DidUpdateRow,
GridNotification::DidUpdateCell,
GridNotification::DidUpdateGrid,
@ -89,11 +89,11 @@ impl ::protobuf::reflect::ProtobufValue for GridNotification {
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x17dart_notification.proto*\x93\x01\n\x10GridNotification\x12\x0b\n\
\x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x12\n\x0eDidUp\
dateBlock\x10\x14\x12\x10\n\x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUpdate\
Cell\x10\x1f\x12\x11\n\rDidUpdateGrid\x10(\x12\x12\n\x0eDidUpdateField\
\x10)b\x06proto3\
\n\x17dart_notification.proto*\x97\x01\n\x10GridNotification\x12\x0b\n\
\x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x16\n\x12DidUp\
dateGridBlock\x10\x14\x12\x10\n\x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUp\
dateCell\x10\x1f\x12\x11\n\rDidUpdateGrid\x10(\x12\x12\n\x0eDidUpdateFie\
ld\x10)b\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -3,7 +3,7 @@ syntax = "proto3";
enum GridNotification {
Unknown = 0;
DidCreateBlock = 11;
DidUpdateBlock = 20;
DidUpdateGridBlock = 20;
DidUpdateRow = 30;
DidUpdateCell = 31;
DidUpdateGrid = 40;

View File

@ -9,7 +9,7 @@ use dashmap::DashMap;
use flowy_error::FlowyResult;
use flowy_grid_data_model::entities::{
CellMeta, CellMetaChangeset, CellNotificationData, FieldMeta, GridBlockMeta, GridBlockMetaChangeset,
GridBlockOrder, RowMeta, RowMetaChangeset, RowOrder,
GridBlockOrder, GridBlockOrderChangeset, RowMeta, RowMetaChangeset, RowOrder,
};
use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
use flowy_revision::{RevisionManager, RevisionPersistence};
@ -70,8 +70,12 @@ impl GridBlockMetaEditorManager {
) -> FlowyResult<i32> {
let _ = self.persistence.insert_or_update(&row_meta.block_id, &row_meta.id)?;
let editor = self.get_editor(&row_meta.block_id).await?;
let row_order = RowOrder::from(&row_meta);
let row_count = editor.create_row(row_meta, start_row_id).await?;
self.notify_block_did_update_row(block_id).await?;
let _ = self
.notify_block_did_update_row(GridBlockOrderChangeset::from_update(block_id, vec![row_order]))
.await?;
Ok(row_count)
}
@ -81,14 +85,18 @@ impl GridBlockMetaEditorManager {
) -> FlowyResult<Vec<GridBlockMetaChangeset>> {
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 {
for row in row_metas {
let _ = self.persistence.insert_or_update(&row.block_id, &row.id)?;
row_count = editor.create_row(row.clone(), None).await?;
inserted_row_orders.push(RowOrder::from(&row));
row_count = editor.create_row(row, None).await?;
}
changesets.push(GridBlockMetaChangeset::from_row_count(&block_id, row_count));
let _ = self.notify_block_did_update_row(&block_id).await?;
let _ = self
.notify_block_did_update_row(GridBlockOrderChangeset::from_insert(&block_id, inserted_row_orders))
.await?;
}
Ok(changesets)
@ -97,7 +105,19 @@ impl GridBlockMetaEditorManager {
pub async fn update_row(&self, changeset: RowMetaChangeset) -> FlowyResult<()> {
let editor = self.get_editor_from_row_id(&changeset.row_id).await?;
let _ = editor.update_row(changeset.clone()).await?;
let _ = self.notify_block_did_update_row(&editor.block_id).await?;
match editor
.get_row_orders(Some(vec![Cow::Borrowed(&changeset.row_id)]))
.await?
.pop()
{
None => {}
Some(row_order) => {
let block_order_changeset = GridBlockOrderChangeset::from_update(&editor.block_id, vec![row_order]);
let _ = self.notify_block_did_update_row(block_order_changeset).await?;
}
}
Ok(())
}
@ -177,11 +197,10 @@ impl GridBlockMetaEditorManager {
Ok(block_cell_metas)
}
async fn notify_block_did_update_row(&self, block_id: &str) -> FlowyResult<()> {
// let block_order: GridBlockOrder = block_id.into();
// send_dart_notification(&self.grid_id, GridNotification::DidUpdateBlock)
// .payload(block_order)
// .send();
async fn notify_block_did_update_row(&self, changeset: GridBlockOrderChangeset) -> FlowyResult<()> {
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridBlock)
.payload(changeset)
.send();
Ok(())
}