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

@ -21,7 +21,7 @@ use collab_plugins::local_storage::CollabPersistenceConfig;
use lib_infra::{if_native, if_wasm};
use parking_lot::{Mutex, RwLock};
use tracing::trace;
use tracing::{error, trace};
#[derive(Clone, Debug)]
pub enum CollabPluginProviderType {
@ -208,33 +208,49 @@ impl AppFlowyCollabBuilder {
#[allow(unused_variables)] persistence_config: CollabPersistenceConfig,
build_config: CollabBuilderConfig,
) -> Result<Arc<MutexCollab>, Error> {
let mut builder = CollabBuilder::new(uid, object_id)
let is_from_doc_state = matches!(collab_doc_state, DocStateSource::FromDocState(_));
let collab = CollabBuilder::new(uid, object_id)
.with_doc_state(collab_doc_state)
.with_device_id(self.device_id.clone());
.with_device_id(self.device_id.clone())
.build()?;
// If the object is from doc state, we need to validate the object type
if is_from_doc_state {
if let Err(err) = object_type.validate(&collab.lock()) {
error!(
"{:?} validation failed: {}, object_id: {}",
object_type, err, object_id
);
return Err(err);
}
}
#[cfg(target_arch = "wasm32")]
{
builder = builder.with_plugin(IndexeddbDiskPlugin::new(
collab.lock().add_plugin(Box::new(IndexeddbDiskPlugin::new(
uid,
object_id.to_string(),
object_type.clone(),
collab_db.clone(),
));
)));
}
#[cfg(not(target_arch = "wasm32"))]
{
builder = builder.with_plugin(RocksdbDiskPlugin::new_with_config(
uid,
object_id.to_string(),
object_type.clone(),
collab_db.clone(),
persistence_config.clone(),
None,
));
collab
.lock()
.add_plugin(Box::new(RocksdbDiskPlugin::new_with_config(
uid,
object_id.to_string(),
object_type.clone(),
collab_db.clone(),
persistence_config.clone(),
None,
)));
}
let collab = Arc::new(builder.build()?);
let arc_collab = Arc::new(collab);
{
let collab_object = self.collab_object(uid, object_id, object_type)?;
if build_config.sync_enable {
@ -244,7 +260,7 @@ impl AppFlowyCollabBuilder {
match provider_type {
CollabPluginProviderType::AppFlowyCloud => {
trace!("init appflowy cloud collab plugins");
let local_collab = Arc::downgrade(&collab);
let local_collab = Arc::downgrade(&arc_collab);
let plugins =
self
.plugin_provider
@ -257,14 +273,14 @@ impl AppFlowyCollabBuilder {
trace!("add appflowy cloud collab plugins: {}", plugins.len());
for plugin in plugins {
collab.lock().add_plugin(plugin);
arc_collab.lock().add_plugin(plugin);
}
},
CollabPluginProviderType::Supabase => {
#[cfg(not(target_arch = "wasm32"))]
{
trace!("init supabase collab plugins");
let local_collab = Arc::downgrade(&collab);
let local_collab = Arc::downgrade(&arc_collab);
let local_collab_db = collab_db.clone();
let plugins =
self
@ -277,7 +293,7 @@ impl AppFlowyCollabBuilder {
local_collab_db,
});
for plugin in plugins {
collab.lock().add_plugin(plugin);
arc_collab.lock().add_plugin(plugin);
}
}
},
@ -287,12 +303,12 @@ impl AppFlowyCollabBuilder {
}
#[cfg(target_arch = "wasm32")]
futures::executor::block_on(collab.lock().initialize());
futures::executor::block_on(arc_collab.lock().initialize());
#[cfg(not(target_arch = "wasm32"))]
collab.lock().initialize();
arc_collab.lock().initialize();
trace!("collab initialized: {}", object_id);
Ok(collab)
Ok(arc_collab)
}
}