Fix some unnecessary-unwraps w/ addl cleanup/simplification.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b3fc8516ed
commit
02081b66c4
6 changed files with 22 additions and 42 deletions
|
@ -142,7 +142,7 @@ pub(crate) async fn sync_events_route(
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// Coalesce database writes for the remainder of this scope.
|
// Coalesce database writes for the remainder of this scope.
|
||||||
let _cork = services().globals.cork_and_flush()?;
|
let _cork = services().globals.db.cork_and_flush();
|
||||||
|
|
||||||
for room_id in all_joined_rooms {
|
for room_id in all_joined_rooms {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
|
|
|
@ -25,15 +25,9 @@ pub trait Data: Send + Sync {
|
||||||
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;
|
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;
|
||||||
fn cleanup(&self) -> Result<()>;
|
fn cleanup(&self) -> Result<()>;
|
||||||
|
|
||||||
/// TODO: use this?
|
fn cork(&self) -> Cork;
|
||||||
#[allow(dead_code)]
|
fn cork_and_flush(&self) -> Cork;
|
||||||
fn flush(&self) -> Result<()>;
|
|
||||||
fn cork(&self) -> Result<Cork>;
|
|
||||||
fn cork_and_flush(&self) -> Result<Cork>;
|
|
||||||
|
|
||||||
/// TODO: use this?
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn cork_and_sync(&self) -> Result<Cork>;
|
|
||||||
fn memory_usage(&self) -> String;
|
fn memory_usage(&self) -> String;
|
||||||
fn clear_caches(&self, amount: u32);
|
fn clear_caches(&self, amount: u32);
|
||||||
fn load_keypair(&self) -> Result<Ed25519KeyPair>;
|
fn load_keypair(&self) -> Result<Ed25519KeyPair>;
|
||||||
|
@ -177,13 +171,9 @@ impl Data for KeyValueDatabase {
|
||||||
|
|
||||||
fn cleanup(&self) -> Result<()> { self.db.cleanup() }
|
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) -> Cork { Cork::new(&self.db, true, 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 memory_usage(&self) -> String {
|
fn memory_usage(&self) -> String {
|
||||||
let auth_chain_cache = self.auth_chain_cache.lock().unwrap().len();
|
let auth_chain_cache = self.auth_chain_cache.lock().unwrap().len();
|
||||||
|
|
|
@ -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::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
fs,
|
fs,
|
||||||
|
@ -29,14 +36,7 @@ use tokio::{
|
||||||
use tracing::{error, trace};
|
use tracing::{error, trace};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{database::Cork, services, Config, Result};
|
use crate::{services, Config, Result};
|
||||||
|
|
||||||
mod client;
|
|
||||||
mod data;
|
|
||||||
pub(crate) mod emerg_access;
|
|
||||||
pub(crate) mod migrations;
|
|
||||||
mod resolver;
|
|
||||||
pub(crate) mod updates;
|
|
||||||
|
|
||||||
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
|
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
|
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 server_name(&self) -> &ServerName { self.config.server_name.as_ref() }
|
||||||
|
|
||||||
pub fn max_request_size(&self) -> u32 { self.config.max_request_size }
|
pub fn max_request_size(&self) -> u32 { self.config.max_request_size }
|
||||||
|
|
|
@ -195,7 +195,7 @@ impl Service {
|
||||||
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
// Coalesce database writes for the remainder of this scope.
|
// Coalesce database writes for the remainder of this scope.
|
||||||
let _cork = services().globals.cork_and_flush()?;
|
let _cork = services().globals.db.cork_and_flush();
|
||||||
|
|
||||||
let shortroomid = services()
|
let shortroomid = services()
|
||||||
.rooms
|
.rooms
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Service {
|
||||||
pub fn send_pdu_push(&self, pdu_id: &[u8], user: &UserId, pushkey: String) -> Result<()> {
|
pub fn send_pdu_push(&self, pdu_id: &[u8], user: &UserId, pushkey: String) -> Result<()> {
|
||||||
let dest = Destination::Push(user.to_owned(), pushkey);
|
let dest = Destination::Push(user.to_owned(), pushkey);
|
||||||
let event = SendingEvent::Pdu(pdu_id.to_owned());
|
let event = SendingEvent::Pdu(pdu_id.to_owned());
|
||||||
let _cork = services().globals.cork()?;
|
let _cork = services().globals.db.cork();
|
||||||
let keys = self.db.queue_requests(&[(&dest, event.clone())])?;
|
let keys = self.db.queue_requests(&[(&dest, event.clone())])?;
|
||||||
self.dispatch(Msg {
|
self.dispatch(Msg {
|
||||||
dest,
|
dest,
|
||||||
|
@ -94,7 +94,7 @@ impl Service {
|
||||||
pub fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec<u8>) -> Result<()> {
|
pub fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec<u8>) -> Result<()> {
|
||||||
let dest = Destination::Appservice(appservice_id);
|
let dest = Destination::Appservice(appservice_id);
|
||||||
let event = SendingEvent::Pdu(pdu_id);
|
let event = SendingEvent::Pdu(pdu_id);
|
||||||
let _cork = services().globals.cork()?;
|
let _cork = services().globals.db.cork();
|
||||||
let keys = self.db.queue_requests(&[(&dest, event.clone())])?;
|
let keys = self.db.queue_requests(&[(&dest, event.clone())])?;
|
||||||
self.dispatch(Msg {
|
self.dispatch(Msg {
|
||||||
dest,
|
dest,
|
||||||
|
@ -121,7 +121,7 @@ impl Service {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|server| (Destination::Normal(server), SendingEvent::Pdu(pdu_id.to_owned())))
|
.map(|server| (Destination::Normal(server), SendingEvent::Pdu(pdu_id.to_owned())))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let _cork = services().globals.cork()?;
|
let _cork = services().globals.db.cork();
|
||||||
let keys = self.db.queue_requests(
|
let keys = self.db.queue_requests(
|
||||||
&requests
|
&requests
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -143,7 +143,7 @@ impl Service {
|
||||||
pub fn send_edu_server(&self, server: &ServerName, serialized: Vec<u8>) -> Result<()> {
|
pub fn send_edu_server(&self, server: &ServerName, serialized: Vec<u8>) -> Result<()> {
|
||||||
let dest = Destination::Normal(server.to_owned());
|
let dest = Destination::Normal(server.to_owned());
|
||||||
let event = SendingEvent::Edu(serialized);
|
let event = SendingEvent::Edu(serialized);
|
||||||
let _cork = services().globals.cork()?;
|
let _cork = services().globals.db.cork();
|
||||||
let keys = self.db.queue_requests(&[(&dest, event.clone())])?;
|
let keys = self.db.queue_requests(&[(&dest, event.clone())])?;
|
||||||
self.dispatch(Msg {
|
self.dispatch(Msg {
|
||||||
dest,
|
dest,
|
||||||
|
@ -170,7 +170,7 @@ impl Service {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|server| (Destination::Normal(server), SendingEvent::Edu(serialized.clone())))
|
.map(|server| (Destination::Normal(server), SendingEvent::Edu(serialized.clone())))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let _cork = services().globals.cork()?;
|
let _cork = services().globals.db.cork();
|
||||||
let keys = self.db.queue_requests(
|
let keys = self.db.queue_requests(
|
||||||
&requests
|
&requests
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl Service {
|
||||||
fn handle_response_ok(
|
fn handle_response_ok(
|
||||||
&self, dest: &Destination, futures: &mut SendingFutures<'_>, statuses: &mut CurTransactionStatus,
|
&self, dest: &Destination, futures: &mut SendingFutures<'_>, statuses: &mut CurTransactionStatus,
|
||||||
) {
|
) {
|
||||||
let _cork = services().globals.cork();
|
let _cork = services().globals.db.cork();
|
||||||
self.db
|
self.db
|
||||||
.delete_all_active_requests_for(dest)
|
.delete_all_active_requests_for(dest)
|
||||||
.expect("all active requests deleted");
|
.expect("all active requests deleted");
|
||||||
|
@ -173,7 +173,7 @@ impl Service {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _cork = services().globals.cork();
|
let _cork = services().globals.db.cork();
|
||||||
let mut events = Vec::new();
|
let mut events = Vec::new();
|
||||||
|
|
||||||
// Must retry any previous transaction for this remote.
|
// Must retry any previous transaction for this remote.
|
||||||
|
@ -187,7 +187,7 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compose the next transaction
|
// Compose the next transaction
|
||||||
let _cork = services().globals.cork();
|
let _cork = services().globals.db.cork();
|
||||||
if !new_events.is_empty() {
|
if !new_events.is_empty() {
|
||||||
self.db.mark_as_active(&new_events)?;
|
self.db.mark_as_active(&new_events)?;
|
||||||
for (e, _) in new_events {
|
for (e, _) in new_events {
|
||||||
|
|
Loading…
Add table
Reference in a new issue