chore: remove lru (#5008)

* chore: remove lru

* chore: update logs

* chore: clippy
This commit is contained in:
Nathan.fooo
2024-03-30 16:28:24 +08:00
committed by GitHub
parent c2c84a5812
commit adc2ee755e
33 changed files with 384 additions and 317 deletions

View File

@ -45,11 +45,20 @@ mime_guess = "2.0"
url = "2.4"
tokio-util = "0.7"
tokio-stream = { workspace = true, features = ["sync"] }
client-api = { version = "0.1.0", features = ["collab-sync", "test_util"] }
lib-dispatch = { workspace = true }
yrs = "0.17.1"
rand = "0.8.5"
[dependencies.client-api]
version = "0.1.0"
features = [
"collab-sync",
"test_util",
# Uncomment the following line to enable verbose logging for sync
# "sync_verbose_log",
]
[dev-dependencies]
uuid.workspace = true
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }

View File

@ -23,7 +23,7 @@ where
object_id: &str,
collab_type: CollabType,
workspace_id: &str,
) -> FutureResult<Vec<u8>, Error> {
) -> FutureResult<Option<Vec<u8>>, Error> {
let workspace_id = workspace_id.to_string();
let object_id = object_id.to_string();
let try_get_client = self.0.try_get_client();
@ -36,10 +36,10 @@ where
},
};
match try_get_client?.get_collab(params).await {
Ok(data) => Ok(data.doc_state.to_vec()),
Ok(data) => Ok(Some(data.doc_state.to_vec())),
Err(err) => {
if err.code == RecordNotFound {
Ok(vec![])
Ok(None)
} else {
Err(Error::new(err))
}

View File

@ -1,5 +1,8 @@
use anyhow::Error;
use collab::preclude::Collab;
use collab_entity::define::{DATABASE, DATABASE_ROW_DATA, WORKSPACE_DATABASES};
use collab_entity::CollabType;
use yrs::{Any, MapPrelim};
use flowy_database_pub::cloud::{CollabDocStateByOid, DatabaseCloudService, DatabaseSnapshot};
use lib_infra::future::FutureResult;
@ -9,11 +12,40 @@ pub(crate) struct LocalServerDatabaseCloudServiceImpl();
impl DatabaseCloudService for LocalServerDatabaseCloudServiceImpl {
fn get_database_object_doc_state(
&self,
_object_id: &str,
_collab_type: CollabType,
object_id: &str,
collab_type: CollabType,
_workspace_id: &str,
) -> FutureResult<Vec<u8>, Error> {
FutureResult::new(async move { Ok(vec![]) })
) -> FutureResult<Option<Vec<u8>>, Error> {
let object_id = object_id.to_string();
// create the minimal required data for the given collab type
FutureResult::new(async move {
let data = match collab_type {
CollabType::Database => {
let collab = Collab::new(1, object_id, collab_type, vec![], false);
collab.with_origin_transact_mut(|txn| {
collab.insert_map_with_txn(txn, DATABASE);
});
collab.encode_collab_v1().doc_state.to_vec()
},
CollabType::WorkspaceDatabase => {
let collab = Collab::new(1, object_id, collab_type, vec![], false);
collab.with_origin_transact_mut(|txn| {
collab.create_array_with_txn::<MapPrelim<Any>>(txn, WORKSPACE_DATABASES, vec![]);
});
collab.encode_collab_v1().doc_state.to_vec()
},
CollabType::DatabaseRow => {
let collab = Collab::new(1, object_id, collab_type, vec![], false);
collab.with_origin_transact_mut(|txn| {
collab.insert_map_with_txn(txn, DATABASE_ROW_DATA);
});
collab.encode_collab_v1().doc_state.to_vec()
},
_ => vec![],
};
Ok(Some(data))
})
}
fn batch_get_database_object_doc_state(

View File

@ -30,7 +30,7 @@ where
object_id: &str,
collab_type: CollabType,
_workspace_id: &str,
) -> FutureResult<Vec<u8>, Error> {
) -> FutureResult<Option<Vec<u8>>, Error> {
let try_get_postgrest = self.server.try_get_weak_postgrest();
let object_id = object_id.to_string();
let (tx, rx) = channel();
@ -41,7 +41,7 @@ where
let updates = FetchObjectUpdateAction::new(object_id.to_string(), collab_type, postgrest)
.run_with_fix_interval(5, 10)
.await?;
Ok(updates)
Ok(Some(updates))
}
.await,
)

View File

@ -284,7 +284,7 @@ pub async fn batch_get_updates_from_server(
match parser_updates_form_json(record.clone(), &postgrest.secret()) {
Ok(items) => {
if items.is_empty() {
updates_by_oid.insert(oid.to_string(), DocStateSource::FromDocState(vec![]));
updates_by_oid.insert(oid.to_string(), DocStateSource::FromDisk);
} else {
let updates = items
.iter()