chore: refactor to use database body
This commit is contained in:
parent
5564fab4c5
commit
7ea6450207
|
|
@ -6,7 +6,6 @@ use collab::preclude::Collab;
|
|||
use collab::preclude::MapExt;
|
||||
use collab_database::database::DatabaseBody;
|
||||
use collab_database::entity::FieldType;
|
||||
use collab_database::views::DatabaseViews;
|
||||
use collab_database::workspace_database::WorkspaceDatabaseBody;
|
||||
use collab_document::blocks::DocumentData;
|
||||
use collab_document::document::Document;
|
||||
|
|
@ -817,25 +816,9 @@ impl PublishCollabDuplicator {
|
|||
let mut new_db_view_ids: Vec<String> = vec![];
|
||||
{
|
||||
let mut txn = db_collab.context.transact_mut();
|
||||
let container = db_collab
|
||||
.data
|
||||
.get(&txn, "database")
|
||||
.ok_or_else(|| AppError::RecordNotFound("no database found in collab".to_string()))?
|
||||
.cast::<MapRef>()
|
||||
.map_err(|err| AppError::Unhandled(format!("not a map: {:?}", err)))?;
|
||||
container.insert(&mut txn, "id", new_db_id.clone());
|
||||
|
||||
let view_map = {
|
||||
let map_ref = db_collab
|
||||
.data
|
||||
.get_with_path(&txn, ["database", "views"])
|
||||
.ok_or_else(|| AppError::RecordNotFound("no views found in database".to_string()))?;
|
||||
DatabaseViews::new(CollabOrigin::Empty, map_ref, None)
|
||||
};
|
||||
|
||||
// create new database views based on published views
|
||||
let mut db_views = view_map.get_all_views(&txn);
|
||||
db_body.root.insert(&mut txn, "id", new_db_id.clone());
|
||||
|
||||
let mut db_views = db_body.views.get_all_views(&txn);
|
||||
for db_view in db_views.iter_mut() {
|
||||
let new_db_view_id = if db_view.id == publish_view_id {
|
||||
self
|
||||
|
|
@ -873,9 +856,9 @@ impl PublishCollabDuplicator {
|
|||
metas.insert(&mut txn, "iid", new_view_id);
|
||||
|
||||
// insert updated views back to db
|
||||
view_map.clear(&mut txn);
|
||||
db_body.views.clear(&mut txn);
|
||||
for view in db_views {
|
||||
view_map.insert_view(&mut txn, view);
|
||||
db_body.views.insert_view(&mut txn, view);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue