apply lint suggestions and version bump

This commit is contained in:
Jonathan de Jong 2021-07-14 12:31:38 +02:00
parent be6b6c3cf0
commit e1b89c1248
11 changed files with 81 additions and 98 deletions

View file

@ -121,7 +121,7 @@ impl Pool {
let spilled = Self::prepare_conn(&self.path, None).unwrap();
return HoldingConn::FromOwned(spilled, spill_arc);
HoldingConn::FromOwned(spilled, spill_arc)
}
}
@ -250,16 +250,7 @@ macro_rules! iter_from_thread {
impl Tree for SqliteTable {
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
let guard = self.engine.pool.read_lock();
// let start = Instant::now();
let val = self.get_with_guard(&guard, key);
// debug!("get: took {:?}", start.elapsed());
// debug!("get key: {:?}", &key)
val
self.get_with_guard(&self.engine.pool.read_lock(), key)
}
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {

View file

@ -16,7 +16,7 @@ use std::{
sync::{Arc, RwLock},
time::{Duration, Instant},
};
use tokio::sync::{broadcast, Semaphore};
use tokio::sync::{broadcast, watch::Receiver, Semaphore};
use trust_dns_resolver::TokioAsyncResolver;
use super::abstraction::Tree;
@ -26,6 +26,11 @@ pub const COUNTER: &[u8] = b"c";
type WellKnownMap = HashMap<Box<ServerName>, (String, String)>;
type TlsNameMap = HashMap<String, webpki::DNSName>;
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
type SyncHandle = (
Option<String>, // since
Receiver<Option<ConduitResult<sync_events::Response>>>, // rx
);
pub struct Globals {
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
pub tls_name_override: Arc<RwLock<TlsNameMap>>,
@ -39,15 +44,7 @@ pub struct Globals {
pub bad_event_ratelimiter: Arc<RwLock<BTreeMap<EventId, RateLimitState>>>,
pub bad_signature_ratelimiter: Arc<RwLock<BTreeMap<Vec<String>, RateLimitState>>>,
pub servername_ratelimiter: Arc<RwLock<BTreeMap<Box<ServerName>, Arc<Semaphore>>>>,
pub sync_receivers: RwLock<
BTreeMap<
(UserId, Box<DeviceId>),
(
Option<String>,
tokio::sync::watch::Receiver<Option<ConduitResult<sync_events::Response>>>,
), // since, rx
>,
>,
pub sync_receivers: RwLock<BTreeMap<(UserId, Box<DeviceId>), SyncHandle>>,
pub rotate: RotationHandler,
}
@ -109,6 +106,12 @@ impl RotationHandler {
}
}
impl Default for RotationHandler {
fn default() -> Self {
Self::new()
}
}
impl Globals {
pub fn load(
globals: Arc<dyn Tree>,

View file

@ -54,6 +54,7 @@ impl Media {
}
/// Uploads or replaces a file thumbnail.
#[allow(clippy::too_many_arguments)]
pub async fn upload_thumbnail(
&self,
mxc: String,

View file

@ -533,17 +533,15 @@ impl Rooms {
r
},
|pduid| {
let r = Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| {
Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| {
Error::bad_database("Invalid pduid in eventid_pduid.")
})?));
r
})?))
},
)?
.map(|pdu| {
let r = serde_json::from_slice(&pdu)
serde_json::from_slice(&pdu)
.map_err(|_| Error::bad_database("Invalid PDU in db."))
.map(Arc::new);
r
.map(Arc::new)
})
.transpose()?
{
@ -1112,7 +1110,7 @@ impl Rooms {
}
};
new_state.insert(shortstatekey, shorteventid.into());
new_state.insert(shortstatekey, shorteventid);
let new_state_hash = self.calculate_hash(
&new_state