chore: use has document api from collab

This commit is contained in:
Zack Fu Zi Xiang 2024-09-12 17:23:30 +08:00
parent dca438b794
commit 0b5ad2162b
No known key found for this signature in database
3 changed files with 39 additions and 42 deletions

12
Cargo.lock generated
View File

@ -2092,7 +2092,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=4025b4f7d013dc0aec137152c7cbf7741e21c0ae#4025b4f7d013dc0aec137152c7cbf7741e21c0ae"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79d74003db11ca431f170de9226eab4b891e7c0f#79d74003db11ca431f170de9226eab4b891e7c0f"
dependencies = [
"anyhow",
"arc-swap",
@ -2117,7 +2117,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=4025b4f7d013dc0aec137152c7cbf7741e21c0ae#4025b4f7d013dc0aec137152c7cbf7741e21c0ae"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79d74003db11ca431f170de9226eab4b891e7c0f#79d74003db11ca431f170de9226eab4b891e7c0f"
dependencies = [
"anyhow",
"async-trait",
@ -2148,7 +2148,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=4025b4f7d013dc0aec137152c7cbf7741e21c0ae#4025b4f7d013dc0aec137152c7cbf7741e21c0ae"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79d74003db11ca431f170de9226eab4b891e7c0f#79d74003db11ca431f170de9226eab4b891e7c0f"
dependencies = [
"anyhow",
"arc-swap",
@ -2168,7 +2168,7 @@ dependencies = [
[[package]]
name = "collab-entity"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=4025b4f7d013dc0aec137152c7cbf7741e21c0ae#4025b4f7d013dc0aec137152c7cbf7741e21c0ae"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79d74003db11ca431f170de9226eab4b891e7c0f#79d74003db11ca431f170de9226eab4b891e7c0f"
dependencies = [
"anyhow",
"bytes",
@ -2187,7 +2187,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=4025b4f7d013dc0aec137152c7cbf7741e21c0ae#4025b4f7d013dc0aec137152c7cbf7741e21c0ae"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79d74003db11ca431f170de9226eab4b891e7c0f#79d74003db11ca431f170de9226eab4b891e7c0f"
dependencies = [
"anyhow",
"arc-swap",
@ -2272,7 +2272,7 @@ dependencies = [
[[package]]
name = "collab-user"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=4025b4f7d013dc0aec137152c7cbf7741e21c0ae#4025b4f7d013dc0aec137152c7cbf7741e21c0ae"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79d74003db11ca431f170de9226eab4b891e7c0f#79d74003db11ca431f170de9226eab4b891e7c0f"
dependencies = [
"anyhow",
"collab",

View File

@ -288,12 +288,12 @@ debug = true
[patch.crates-io]
# It's diffcult to resovle different version with the same crate used in AppFlowy Frontend and the Client-API crate.
# So using patch to workaround this issue.
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "4025b4f7d013dc0aec137152c7cbf7741e21c0ae" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "4025b4f7d013dc0aec137152c7cbf7741e21c0ae" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "4025b4f7d013dc0aec137152c7cbf7741e21c0ae" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "4025b4f7d013dc0aec137152c7cbf7741e21c0ae" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "4025b4f7d013dc0aec137152c7cbf7741e21c0ae" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "4025b4f7d013dc0aec137152c7cbf7741e21c0ae" }
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79d74003db11ca431f170de9226eab4b891e7c0f" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79d74003db11ca431f170de9226eab4b891e7c0f" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79d74003db11ca431f170de9226eab4b891e7c0f" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79d74003db11ca431f170de9226eab4b891e7c0f" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79d74003db11ca431f170de9226eab4b891e7c0f" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79d74003db11ca431f170de9226eab4b891e7c0f" }
[features]
history = []

View File

@ -754,44 +754,41 @@ impl PublishCollabDuplicator {
db_row_body
.get_data()
.insert(&mut txn, ROW_DATABASE_ID, new_db_id.clone());
{
// handle document in database row
let pub_is_doc_empty_key =
meta_id_from_row_id(&pub_row_id.parse()?, RowMetaKey::IsDocumentEmpty);
let pub_is_doc_empty = db_row_body.get_meta().get(&txn, &pub_is_doc_empty_key);
if let Some(Out::Any(Any::Bool(is_doc_empty))) = pub_is_doc_empty {
if !is_doc_empty {
// handle document in database row
match db_row_body.has_document(&txn) {
Ok(has_doc) => {
if has_doc {
let pub_row_doc_id =
meta_id_from_row_id(&pub_row_id.parse()?, RowMetaKey::DocumentId);
let row_doc_doc_state = match published_db
match published_db
.database_row_document_collabs
.get(&pub_row_doc_id)
{
Some(doc_state) => doc_state,
None => {
tracing::error!("no document found for row: {}", pub_row_doc_id);
continue;
Some(row_doc_doc_state) => {
let pub_doc_collab =
collab_from_doc_state(row_doc_doc_state.to_vec(), &pub_row_doc_id)?;
let pub_doc = Document::open(pub_doc_collab)
.map_err(|e| AppError::Unhandled(e.to_string()))?;
let dup_row_doc_id =
meta_id_from_row_id(&dup_row_id.parse()?, RowMetaKey::DocumentId);
let mut new_doc_view = Box::pin(self.deep_copy_doc(
&pub_row_doc_id,
dup_row_doc_id.clone(),
pub_doc,
PublishViewMetaData::default(),
))
.await?;
new_doc_view.parent_view_id.clone_from(&dup_row_doc_id); // orphan folder view
self
.views_to_add
.insert(dup_row_doc_id.clone(), new_doc_view);
},
None => tracing::error!("no document found for row: {}", pub_row_doc_id),
};
let pub_doc_collab =
collab_from_doc_state(row_doc_doc_state.to_vec(), &pub_row_doc_id)?;
let pub_doc =
Document::open(pub_doc_collab).map_err(|e| AppError::Unhandled(e.to_string()))?;
let dup_row_doc_id =
meta_id_from_row_id(&dup_row_id.parse()?, RowMetaKey::DocumentId);
let mut new_doc_view = Box::pin(self.deep_copy_doc(
&pub_row_doc_id,
dup_row_doc_id.clone(),
pub_doc,
PublishViewMetaData::default(),
))
.await?;
new_doc_view.parent_view_id.clone_from(&dup_row_doc_id); // orphan folder view
self
.views_to_add
.insert(dup_row_doc_id.clone(), new_doc_view);
}
}
},
Err(err) => tracing::error!("failed to check if row has document: {}", err),
}
db_row_body