mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: start init sync when open document/database (#5040)
This commit is contained in:
@ -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) {
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user