split remaining map suites

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-29 07:37:43 +00:00 committed by strawberry
parent 4496cf2d5b
commit 5192927a53
9 changed files with 205 additions and 180 deletions

View file

@ -3,7 +3,7 @@ use std::{
sync::{Arc, RwLock},
};
use conduit::{trace, utils, Error, Result, Server};
use conduit::{trace, utils, utils::rand, Error, Result, Server};
use database::{Database, Deserialized, Map};
use futures::{pin_mut, stream::FuturesUnordered, FutureExt, StreamExt};
use ruma::{
@ -102,7 +102,7 @@ impl Data {
fn stored_count(global: &Arc<Map>) -> Result<u64> {
global
.get(COUNTER)
.get_blocking(COUNTER)
.as_deref()
.map_or(Ok(0_u64), utils::u64_from_bytes)
}
@ -206,17 +206,23 @@ impl Data {
}
pub fn load_keypair(&self) -> Result<Ed25519KeyPair> {
let keypair_bytes = self.global.get(b"keypair").map_or_else(
|_| {
let keypair = utils::generate_keypair();
self.global.insert(b"keypair", &keypair);
Ok::<_, Error>(keypair)
},
|val| Ok(val.to_vec()),
)?;
let generate = |_| {
let keypair = Ed25519KeyPair::generate().expect("Ed25519KeyPair generation always works (?)");
let mut value = rand::string(8).as_bytes().to_vec();
value.push(0xFF);
value.extend_from_slice(&keypair);
self.global.insert(b"keypair", &value);
value
};
let keypair_bytes: Vec<u8> = self
.global
.get_blocking(b"keypair")
.map_or_else(generate, Into::into);
let mut parts = keypair_bytes.splitn(2, |&b| b == 0xFF);
utils::string_from_bytes(
// 1. version
parts

View file

@ -59,7 +59,7 @@ impl Data {
for (i, short) in self
.eventid_shorteventid
.multi_get(keys.iter())
.get_batch_blocking(keys.iter())
.iter()
.enumerate()
{

View file

@ -326,7 +326,7 @@ pub(super) fn pdu_count(pdu_id: &[u8]) -> PduCount {
//TODO: this is an ABA
fn increment(db: &Arc<Map>, key: &[u8]) {
let old = db.get(key);
let old = db.get_blocking(key);
let new = utils::increment(old.ok().as_deref());
db.insert(key, &new);
}

View file

@ -1000,7 +1000,7 @@ where
//TODO: this is an ABA
fn increment(db: &Arc<Map>, key: &[u8]) {
let old = db.get(key);
let old = db.get_blocking(key);
let new = utils::increment(old.ok().as_deref());
db.insert(key, &new);
}