Fix some unnecessary-unwraps w/ addl cleanup/simplification.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-02 00:18:57 +00:00 committed by June 🍓🦴
parent b3fc8516ed
commit 02081b66c4
6 changed files with 22 additions and 42 deletions

View file

@ -25,15 +25,9 @@ pub trait Data: Send + Sync {
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;
fn cleanup(&self) -> Result<()>;
/// TODO: use this?
#[allow(dead_code)]
fn flush(&self) -> Result<()>;
fn cork(&self) -> Result<Cork>;
fn cork_and_flush(&self) -> Result<Cork>;
fn cork(&self) -> Cork;
fn cork_and_flush(&self) -> Cork;
/// TODO: use this?
#[allow(dead_code)]
fn cork_and_sync(&self) -> Result<Cork>;
fn memory_usage(&self) -> String;
fn clear_caches(&self, amount: u32);
fn load_keypair(&self) -> Result<Ed25519KeyPair>;
@ -177,13 +171,9 @@ impl Data for KeyValueDatabase {
fn cleanup(&self) -> Result<()> { self.db.cleanup() }
fn flush(&self) -> Result<()> { self.db.flush() }
fn cork(&self) -> Cork { Cork::new(&self.db, false, false) }
fn cork(&self) -> Result<Cork> { Ok(Cork::new(&self.db, false, false)) }
fn cork_and_flush(&self) -> Result<Cork> { Ok(Cork::new(&self.db, true, false)) }
fn cork_and_sync(&self) -> Result<Cork> { Ok(Cork::new(&self.db, true, true)) }
fn cork_and_flush(&self) -> Cork { Cork::new(&self.db, true, false) }
fn memory_usage(&self) -> String {
let auth_chain_cache = self.auth_chain_cache.lock().unwrap().len();

View file

@ -1,3 +1,10 @@
mod client;
mod data;
pub(super) mod emerg_access;
pub(super) mod migrations;
mod resolver;
pub(super) mod updates;
use std::{
collections::{BTreeMap, HashMap},
fs,
@ -29,14 +36,7 @@ use tokio::{
use tracing::{error, trace};
use url::Url;
use crate::{database::Cork, services, Config, Result};
mod client;
mod data;
pub(crate) mod emerg_access;
pub(crate) mod migrations;
mod resolver;
pub(crate) mod updates;
use crate::{services, Config, Result};
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
@ -194,16 +194,6 @@ impl Service {
self.db.watch(user_id, device_id).await
}
pub fn cleanup(&self) -> Result<()> { self.db.cleanup() }
/// TODO: use this?
#[allow(dead_code)]
pub fn flush(&self) -> Result<()> { self.db.flush() }
pub fn cork(&self) -> Result<Cork> { self.db.cork() }
pub fn cork_and_flush(&self) -> Result<Cork> { self.db.cork_and_flush() }
pub fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() }
pub fn max_request_size(&self) -> u32 { self.config.max_request_size }