fix: compile errors (#2310)

This commit is contained in:
Nathan.fooo
2023-04-21 17:02:26 +08:00
committed by GitHub
parent c009347735
commit 0068c7e731
12 changed files with 384 additions and 46 deletions

View File

@ -1,4 +1,4 @@
use collab_persistence::CollabKV;
use collab_persistence::kv::rocks_kv::RocksCollabDB;
use flowy_error::FlowyError;
use flowy_sqlite::ConnectionPool;
use flowy_sqlite::{schema::user_table, DBConnection, Database};
@ -47,12 +47,12 @@ impl UserDB {
Ok(pool)
}
fn open_kv_db_if_need(&self, user_id: i64) -> Result<Arc<CollabKV>, FlowyError> {
if let Some(kv) = KVDB_MAP.read().get(&user_id) {
fn open_kv_db_if_need(&self, user_id: i64) -> Result<Arc<RocksCollabDB>, FlowyError> {
if let Some(kv) = COLLAB_DB_MAP.read().get(&user_id) {
return Ok(kv.clone());
}
let mut write_guard = KVDB_MAP.write();
let mut write_guard = COLLAB_DB_MAP.write();
// The Write guard acquire exclusive access that will guarantee the user db only initialize once.
match write_guard.get(&user_id) {
None => {},
@ -64,8 +64,8 @@ impl UserDB {
dir.push(user_id.to_string());
tracing::trace!("open kv db {} at path: {:?}", user_id, dir);
let kv_db = CollabKV::open(dir).map_err(|err| FlowyError::internal().context(err))?;
let kv_db = Arc::new(kv_db);
let db = RocksCollabDB::open(dir).map_err(|err| FlowyError::internal().context(err))?;
let kv_db = Arc::new(db);
write_guard.insert(user_id.to_owned(), kv_db.clone());
drop(write_guard);
Ok(kv_db)
@ -91,7 +91,7 @@ impl UserDB {
Ok(pool)
}
pub(crate) fn get_kv_db(&self, user_id: i64) -> Result<Arc<CollabKV>, FlowyError> {
pub(crate) fn get_kv_db(&self, user_id: i64) -> Result<Arc<RocksCollabDB>, FlowyError> {
let kv_db = self.open_kv_db_if_need(user_id)?;
Ok(kv_db)
}
@ -99,7 +99,7 @@ impl UserDB {
lazy_static! {
static ref DB_MAP: RwLock<HashMap<i64, Database>> = RwLock::new(HashMap::new());
static ref KVDB_MAP: RwLock<HashMap<i64, Arc<CollabKV>>> = RwLock::new(HashMap::new());
static ref COLLAB_DB_MAP: RwLock<HashMap<i64, Arc<RocksCollabDB>>> = RwLock::new(HashMap::new());
}
#[derive(Clone, Default, Queryable, Identifiable, Insertable)]

View File

@ -7,7 +7,7 @@ use crate::{
notification::*,
services::database::{UserDB, UserTable, UserTableChangeset},
};
use collab_persistence::CollabKV;
use collab_persistence::kv::rocks_kv::RocksCollabDB;
use flowy_sqlite::ConnectionPool;
use flowy_sqlite::{
kv::KV,
@ -125,7 +125,7 @@ impl UserSession {
self.database.get_pool(user_id)
}
pub fn get_kv_db(&self) -> Result<Arc<CollabKV>, FlowyError> {
pub fn get_kv_db(&self) -> Result<Arc<RocksCollabDB>, FlowyError> {
let user_id = self.get_session()?.user_id;
self.database.get_kv_db(user_id)
}