chore: fix database row sync (#4964)

* chore: fix database row sync

* ci: fix test

* ci: fix web build

* chore: bump collab
This commit is contained in:
Nathan.fooo
2024-03-23 09:18:47 +08:00
committed by GitHub
parent c0642d3ff3
commit b307312a71
45 changed files with 364 additions and 347 deletions

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::num::NonZeroUsize;
use std::sync::{Arc, Weak};
use collab::core::collab::{CollabDocState, MutexCollab};
use collab::core::collab::{DocStateSource, MutexCollab};
use collab_database::blocks::BlockEvent;
use collab_database::database::{get_inline_view_id, DatabaseData, MutexDatabase};
use collab_database::error::DatabaseError;
@ -12,7 +12,7 @@ use collab_database::user::{
use collab_database::views::{CreateDatabaseParams, CreateViewParams, DatabaseLayout};
use collab_entity::CollabType;
use collab_plugins::local_storage::kv::KVTransactionDB;
use futures::executor::block_on;
use lru::LruCache;
use tokio::sync::{Mutex, RwLock};
use tracing::{event, instrument, trace};
@ -98,7 +98,7 @@ impl DatabaseManager {
};
let config = CollabPersistenceConfig::new().snapshot_per_update(100);
let mut workspace_database_doc_state = CollabDocState::default();
let mut workspace_database_doc_state = DocStateSource::FromDisk;
// If the workspace database not exist in disk, try to fetch from remote.
if !self.is_collab_exist(uid, &collab_db, &workspace_database_object_id) {
trace!("workspace database not exist, try to fetch from remote");
@ -111,8 +111,8 @@ impl DatabaseManager {
)
.await
{
Ok(remote_doc_state) => {
workspace_database_doc_state = remote_doc_state;
Ok(doc_state) => {
workspace_database_doc_state = DocStateSource::FromDocState(doc_state);
},
Err(err) => {
return Err(FlowyError::record_not_found().with_context(format!(
@ -423,7 +423,7 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
&self,
object_id: &str,
object_ty: CollabType,
) -> CollabFuture<Result<CollabDocState, DatabaseError>> {
) -> CollabFuture<Result<DocStateSource, DatabaseError>> {
let workspace_id = self.workspace_id.clone();
let object_id = object_id.to_string();
let weak_cloud_service = Arc::downgrade(&self.cloud_service);
@ -431,13 +431,13 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
match weak_cloud_service.upgrade() {
None => {
tracing::warn!("Cloud service is dropped");
Ok(vec![])
Ok(DocStateSource::FromDocState(vec![]))
},
Some(cloud_service) => {
let updates = cloud_service
let doc_state = cloud_service
.get_database_object_doc_state(&object_id, object_ty, &workspace_id)
.await?;
Ok(updates)
Ok(DocStateSource::FromDocState(doc_state))
},
}
})
@ -472,18 +472,20 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
object_id: &str,
object_type: CollabType,
collab_db: Weak<CollabKVDB>,
collab_raw_data: CollabDocState,
collab_raw_data: DocStateSource,
persistence_config: CollabPersistenceConfig,
) -> Arc<MutexCollab> {
block_on(self.collab_builder.build_with_config(
uid,
object_id,
object_type,
collab_db,
collab_raw_data,
persistence_config,
CollabBuilderConfig::default().sync_enable(true),
))
.unwrap()
self
.collab_builder
.build_with_config(
uid,
object_id,
object_type,
collab_db,
collab_raw_data,
persistence_config,
CollabBuilderConfig::default().sync_enable(true),
)
.unwrap()
}
}

View File

@ -805,6 +805,7 @@ impl DatabaseEditor {
}?;
(field, database.get_cell(field_id, &row_id).cell)
};
let new_cell =
apply_cell_changeset(cell_changeset, cell, &field, Some(self.cell_cache.clone()))?;
self.update_cell(view_id, row_id, field_id, new_cell).await