chore: use collab to bin

This commit is contained in:
nathan 2024-09-16 16:45:47 +08:00
parent 8523c8efcf
commit fa54f79d8b
1 changed files with 17 additions and 25 deletions

View File

@ -421,17 +421,10 @@ impl PublishCollabDuplicator {
.map_err(|e| AppError::Unhandled(e.to_string())) .map_err(|e| AppError::Unhandled(e.to_string()))
}) })
.await??; .await??;
let new_doc_bin = tokio::task::spawn_blocking(move || { let new_doc_bin = collab_to_bin(&new_doc, CollabType::Document).await?;
new_doc
.encode_collab()
.map_err(|e| AppError::Unhandled(e.to_string()))
.map(|ec| ec.encode_to_bytes())
})
.await?;
self self
.collabs_to_insert .collabs_to_insert
.insert(ret_view.id.clone(), (CollabType::Document, new_doc_bin??)); .insert(ret_view.id.clone(), (CollabType::Document, new_doc_bin));
} }
Ok(ret_view) Ok(ret_view)
} }
@ -854,12 +847,10 @@ impl PublishCollabDuplicator {
} }
// write new row collab to storage // write new row collab to storage
let db_row_ec_bytes = let db_row_ec_bytes = collab_to_bin(&db_row_collab, CollabType::DatabaseRow).await?;
tokio::task::spawn_blocking(move || collab_to_bin(&db_row_collab, CollabType::DatabaseRow))
.await?;
self.collabs_to_insert.insert( self.collabs_to_insert.insert(
dup_row_id.clone(), dup_row_id.clone(),
(CollabType::DatabaseRow, db_row_ec_bytes?), (CollabType::DatabaseRow, db_row_ec_bytes),
); );
self self
.duplicated_db_row .duplicated_db_row
@ -913,12 +904,10 @@ impl PublishCollabDuplicator {
} }
// write database collab to storage // write database collab to storage
let db_encoded_collab = let db_encoded_collab = collab_to_bin(&db_collab, CollabType::Database).await?;
tokio::task::spawn_blocking(move || collab_to_bin(&db_collab, CollabType::Database)).await?; self
self.collabs_to_insert.insert( .collabs_to_insert
new_db_id.clone(), .insert(new_db_id.clone(), (CollabType::Database, db_encoded_collab));
(CollabType::Database, db_encoded_collab?),
);
// Add this database as linked view // Add this database as linked view
self self
@ -1154,10 +1143,13 @@ fn to_folder_view_layout(layout: workspace_dto::ViewLayout) -> collab_folder::Vi
} }
} }
fn collab_to_bin(collab: &Collab, collab_type: CollabType) -> Result<Vec<u8>, AppError> { async fn collab_to_bin(collab: &Collab, collab_type: CollabType) -> Result<Vec<u8>, AppError> {
let bin = collab tokio::task::spawn_blocking(move || {
.encode_collab_v1(|collab| collab_type.validate_require_data(collab)) let bin = collab
.map_err(|e| AppError::Unhandled(e.to_string()))? .encode_collab_v1(|collab| collab_type.validate_require_data(collab))
.encode_to_bytes()?; .map_err(|e| AppError::Unhandled(e.to_string()))?
Ok(bin) .encode_to_bytes()?;
Ok(bin)
})
.await?
} }