refactor: fix warnings

This commit is contained in:
Timo Kösters 2022-01-17 14:39:37 +01:00
parent ee8e72f7a8
commit 8c90e7adfb
No known key found for this signature in database
GPG Key ID: 356E705610F626D5
4 changed files with 24 additions and 37 deletions

View File

@ -4,7 +4,6 @@ use std::{future::Future, pin::Pin, sync::Arc, sync::RwLock};
pub struct Engine {
rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>,
cache_capacity_bytes: usize,
max_open_files: i32,
cache: rocksdb::Cache,
old_cfs: Vec<String>,
@ -17,11 +16,7 @@ pub struct RocksDbEngineTree<'a> {
write_lock: RwLock<()>,
}
fn db_options(
cache_capacity_bytes: usize,
max_open_files: i32,
rocksdb_cache: &rocksdb::Cache,
) -> rocksdb::Options {
fn db_options(max_open_files: i32, rocksdb_cache: &rocksdb::Cache) -> rocksdb::Options {
let mut block_based_options = rocksdb::BlockBasedOptions::default();
block_based_options.set_block_cache(rocksdb_cache);
@ -57,11 +52,7 @@ impl DatabaseEngine for Arc<Engine> {
let cache_capacity_bytes = (config.db_cache_capacity_mb * 1024.0 * 1024.0) as usize;
let rocksdb_cache = rocksdb::Cache::new_lru_cache(cache_capacity_bytes).unwrap();
let db_opts = db_options(
cache_capacity_bytes,
config.rocksdb_max_open_files,
&rocksdb_cache,
);
let db_opts = db_options(config.rocksdb_max_open_files, &rocksdb_cache);
let cfs = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::list_cf(
&db_opts,
@ -75,18 +66,13 @@ impl DatabaseEngine for Arc<Engine> {
cfs.iter().map(|name| {
rocksdb::ColumnFamilyDescriptor::new(
name,
db_options(
cache_capacity_bytes,
config.rocksdb_max_open_files,
&rocksdb_cache,
),
db_options(config.rocksdb_max_open_files, &rocksdb_cache),
)
}),
)?;
Ok(Arc::new(Engine {
rocks: db,
cache_capacity_bytes,
max_open_files: config.rocksdb_max_open_files,
cache: rocksdb_cache,
old_cfs: cfs,
@ -96,10 +82,9 @@ impl DatabaseEngine for Arc<Engine> {
fn open_tree(&self, name: &'static str) -> Result<Arc<dyn Tree>> {
if !self.old_cfs.contains(&name.to_owned()) {
// Create if it didn't exist
let _ = self.rocks.create_cf(
name,
&db_options(self.cache_capacity_bytes, self.max_open_files, &self.cache),
);
let _ = self
.rocks
.create_cf(name, &db_options(self.max_open_files, &self.cache));
}
Ok(Arc::new(RocksDbEngineTree {

View File

@ -534,7 +534,8 @@ impl Sending {
.collect::<Vec<_>>(),
),
base64::URL_SAFE_NO_PAD,
)).into(),
))
.into(),
},
)
.await
@ -692,7 +693,8 @@ impl Sending {
.collect::<Vec<_>>(),
),
base64::URL_SAFE_NO_PAD,
)).into(),
))
.into(),
},
)
.await

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use crate::Result;
use ruma::{DeviceId, UserId, identifiers::TransactionId};
use ruma::{identifiers::TransactionId, DeviceId, UserId};
use super::abstraction::Tree;

View File

@ -42,9 +42,9 @@ use ruma::{
events::{
receipt::{ReceiptEvent, ReceiptEventContent},
room::{
server_acl::RoomServerAclEventContent,
create::RoomCreateEventContent,
member::{MembershipState, RoomMemberEventContent},
server_acl::RoomServerAclEventContent,
},
AnyEphemeralRoomEvent, EventType,
},
@ -3491,20 +3491,17 @@ pub(crate) async fn fetch_join_signing_keys(
}
/// Returns Ok if the acl allows the server
fn acl_check(
server_name: &ServerName,
room_id: &RoomId,
db: &Database,
) -> Result<()> {
fn acl_check(server_name: &ServerName, room_id: &RoomId, db: &Database) -> Result<()> {
let acl_event = match db
.rooms
.room_state_get(room_id, &EventType::RoomServerAcl, "")? {
Some(acl) => acl,
None => return Ok(()),
};
.room_state_get(room_id, &EventType::RoomServerAcl, "")?
{
Some(acl) => acl,
None => return Ok(()),
};
let acl_event_content: RoomServerAclEventContent = match
serde_json::from_str(acl_event.content.get()) {
let acl_event_content: RoomServerAclEventContent =
match serde_json::from_str(acl_event.content.get()) {
Ok(content) => content,
Err(_) => {
warn!("Invalid ACL event");
@ -3515,7 +3512,10 @@ fn acl_check(
if acl_event_content.is_allowed(server_name) {
Ok(())
} else {
Err(Error::BadRequest(ErrorKind::Forbidden, "Server was denied by ACL"))
Err(Error::BadRequest(
ErrorKind::Forbidden,
"Server was denied by ACL",
))
}
}