improvement: allow batch inserts
parent
0eeba86b32
commit
49ade0cfbd
|
@ -484,6 +484,16 @@ impl Database {
|
||||||
.watch_prefix(&userid_prefix),
|
.watch_prefix(&userid_prefix),
|
||||||
);
|
);
|
||||||
futures.push(self.rooms.userroomid_leftstate.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
|
// Events for rooms we are in
|
||||||
for room_id in self.rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
|
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 get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
||||||
|
|
||||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
|
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<()>;
|
fn remove(&self, key: &[u8]) -> Result<()>;
|
||||||
|
|
||||||
|
|
|
@ -201,6 +201,21 @@ impl Tree for SqliteTable {
|
||||||
Ok(())
|
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))]
|
#[tracing::instrument(skip(self, key))]
|
||||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||||
let guard = self.engine.write_lock();
|
let guard = self.engine.write_lock();
|
||||||
|
@ -228,7 +243,7 @@ impl Tree for SqliteTable {
|
||||||
|
|
||||||
let statement = Box::leak(Box::new(
|
let statement = Box::leak(Box::new(
|
||||||
guard
|
guard
|
||||||
.prepare(&format!("SELECT key, value FROM {}", &self.name))
|
.prepare(&format!("SELECT key, value FROM {} ORDER BY key ASC", &self.name))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue