mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-04 17:29:14 +01:00
improvement: allow batch inserts
This commit is contained in:
parent
0eeba86b32
commit
49ade0cfbd
3 changed files with 27 additions and 1 deletions
|
@ -484,6 +484,16 @@ impl Database {
|
|||
.watch_prefix(&userid_prefix),
|
||||
);
|
||||
futures.push(self.rooms.userroomid_leftstate.watch_prefix(&userid_prefix));
|
||||
futures.push(
|
||||
self.rooms
|
||||
.userroomid_notificationcount
|
||||
.watch_prefix(&userid_prefix),
|
||||
);
|
||||
futures.push(
|
||||
self.rooms
|
||||
.userroomid_highlightcount
|
||||
.watch_prefix(&userid_prefix),
|
||||
);
|
||||
|
||||
// Events for rooms we are in
|
||||
for room_id in self.rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
|
||||
|
|
|
@ -25,6 +25,7 @@ pub trait Tree: Send + Sync {
|
|||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
|
||||
fn insert_batch<'a>(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>;
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()>;
|
||||
|
||||
|
|
|
@ -201,6 +201,21 @@ impl Tree for SqliteTable {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, iter))]
|
||||
fn insert_batch<'a>(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()> {
|
||||
let guard = self.engine.write_lock();
|
||||
|
||||
guard.execute("BEGIN", [])?;
|
||||
for (key, value) in iter {
|
||||
self.insert_with_guard(&guard, &key, &value)?;
|
||||
}
|
||||
guard.execute("COMMIT", [])?;
|
||||
|
||||
drop(guard);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, key))]
|
||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||
let guard = self.engine.write_lock();
|
||||
|
@ -228,7 +243,7 @@ impl Tree for SqliteTable {
|
|||
|
||||
let statement = Box::leak(Box::new(
|
||||
guard
|
||||
.prepare(&format!("SELECT key, value FROM {}", &self.name))
|
||||
.prepare(&format!("SELECT key, value FROM {} ORDER BY key ASC", &self.name))
|
||||
.unwrap(),
|
||||
));
|
||||
|
||||
|
|
Loading…
Reference in a new issue