simplify cork interface related

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-01 20:54:38 +00:00
parent a1ced0a56f
commit 6dd6e4bfaf
10 changed files with 26 additions and 22 deletions

View file

@ -9,7 +9,7 @@ pub struct Cork {
}
impl Cork {
pub fn new(db: &Arc<Engine>, flush: bool, sync: bool) -> Self {
pub(super) fn new(db: &Arc<Engine>, flush: bool, sync: bool) -> Self {
db.cork();
Self {
db: db.clone(),

View file

@ -8,7 +8,7 @@ use conduit::{PduCount, Result, Server};
use lru_cache::LruCache;
use ruma::{CanonicalJsonValue, OwnedDeviceId, OwnedRoomId, OwnedUserId};
use crate::{maps, maps::Maps, Engine, Map};
use crate::{cork::Cork, maps, maps::Maps, Engine, Map};
pub struct Database {
pub db: Arc<Engine>,
@ -38,6 +38,15 @@ impl Database {
)),
})
}
#[must_use]
pub fn cork(&self) -> Cork { Cork::new(&self.db, false, false) }
#[must_use]
pub fn cork_and_flush(&self) -> Cork { Cork::new(&self.db, true, false) }
#[must_use]
pub fn cork_and_sync(&self) -> Cork { Cork::new(&self.db, true, true) }
}
impl Index<&str> for Database {

View file

@ -122,7 +122,7 @@ impl Engine {
pub fn sync(&self) -> Result<()> { result(DBCommon::flush_wal(&self.db, true)) }
pub(crate) fn corked(&self) -> bool { self.corks.load(std::sync::atomic::Ordering::Relaxed) > 0 }
pub fn corked(&self) -> bool { self.corks.load(std::sync::atomic::Ordering::Relaxed) > 0 }
pub(crate) fn cork(&self) {
self.corks

View file

@ -1,4 +1,4 @@
pub mod cork;
mod cork;
mod database;
mod engine;
mod map;
@ -10,7 +10,6 @@ mod watchers;
extern crate conduit_core as conduit;
extern crate rust_rocksdb as rocksdb;
pub use cork::Cork;
pub use database::Database;
pub(crate) use engine::Engine;
pub use map::Map;