chore: start init sync when open document/database (#5040)

This commit is contained in:
Nathan.fooo
2024-04-02 22:15:42 +08:00
committed by GitHub
parent 419600ca11
commit dff3ea60bd
12 changed files with 258 additions and 88 deletions

View File

@ -12,7 +12,7 @@ use std::{
ops::{Deref, DerefMut},
sync::Arc,
};
use tracing::trace;
use tracing::{instrument, trace, warn};
/// This struct wrap the document::Document
#[derive(Clone)]
@ -47,6 +47,19 @@ impl MutexDocument {
Document::create_with_data(collab, data).map(|inner| Self(Arc::new(Mutex::new(inner))))?;
Ok(document)
}
#[instrument(level = "debug", skip_all)]
pub fn start_init_sync(&self) {
if let Some(document) = self.0.try_lock() {
if let Some(collab) = document.get_collab().try_lock() {
collab.start_init_sync();
} else {
warn!("Failed to start init sync, collab is locked");
}
} else {
warn!("Failed to start init sync, document is locked");
}
}
}
fn subscribe_document_changed(doc_id: &str, document: &MutexDocument) {

View File

@ -207,8 +207,9 @@ impl DocumentManager {
}
pub async fn open_document(&self, doc_id: &str) -> FlowyResult<()> {
// TODO(nathan): refactor the get_database that split the database creation and database opening.
self.restore_document_from_removing(doc_id);
if let Some(mutex_document) = self.restore_document_from_removing(doc_id) {
mutex_document.start_init_sync();
}
Ok(())
}