go through a ton of pedantic clippy lints

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-02 20:55:02 -05:00 committed by June
parent 33727a3423
commit e2c7afe69c
61 changed files with 282 additions and 247 deletions

View file

@ -40,7 +40,6 @@ fn db_options(rocksdb_cache: &rocksdb::Cache, config: &Config) -> rocksdb::Optio
let rocksdb_log_level = match config.rocksdb_log_level.as_ref() {
"debug" => Debug,
"info" => Info,
"warn" => Warn,
"error" => Error,
"fatal" => Fatal,
_ => Warn,
@ -71,7 +70,7 @@ fn db_options(rocksdb_cache: &rocksdb::Cache, config: &Config) -> rocksdb::Optio
db_opts.set_block_based_table_factory(&block_based_options);
db_opts.set_level_compaction_dynamic_level_bytes(true);
db_opts.create_if_missing(true);
db_opts.increase_parallelism(num_cpus::get() as i32);
db_opts.increase_parallelism(num_cpus::get().try_into().unwrap_or_default());
//db_opts.set_max_open_files(config.rocksdb_max_open_files);
db_opts.set_compression_type(rocksdb::DBCompressionType::Zstd);
db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level);
@ -79,7 +78,7 @@ fn db_options(rocksdb_cache: &rocksdb::Cache, config: &Config) -> rocksdb::Optio
// https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning
db_opts.set_max_background_jobs(6);
db_opts.set_bytes_per_sync(1048576);
db_opts.set_bytes_per_sync(1_048_576);
// https://github.com/facebook/rocksdb/wiki/WAL-Recovery-Modes#ktoleratecorruptedtailrecords
//

View file

@ -21,7 +21,7 @@ impl service::account_data::Data for KeyValueDatabase {
data: &serde_json::Value,
) -> Result<()> {
let mut prefix = room_id
.map(|r| r.to_string())
.map(std::string::ToString::to_string)
.unwrap_or_default()
.as_bytes()
.to_vec();
@ -71,7 +71,7 @@ impl service::account_data::Data for KeyValueDatabase {
kind: RoomAccountDataEventType,
) -> Result<Option<Box<serde_json::value::RawValue>>> {
let mut key = room_id
.map(|r| r.to_string())
.map(std::string::ToString::to_string)
.unwrap_or_default()
.as_bytes()
.to_vec();
@ -106,7 +106,7 @@ impl service::account_data::Data for KeyValueDatabase {
let mut userdata = HashMap::new();
let mut prefix = room_id
.map(|r| r.to_string())
.map(std::string::ToString::to_string)
.unwrap_or_default()
.as_bytes()
.to_vec();

View file

@ -13,7 +13,7 @@ impl service::appservice::Data for KeyValueDatabase {
self.cached_registrations
.write()
.unwrap()
.insert(id.to_owned(), yaml.to_owned());
.insert(id.to_owned(), yaml.clone());
Ok(id.to_owned())
}
@ -67,7 +67,7 @@ impl service::appservice::Data for KeyValueDatabase {
fn all(&self) -> Result<Vec<(String, Registration)>> {
self.iter_ids()?
.filter_map(|id| id.ok())
.filter_map(std::result::Result::ok)
.map(move |id| {
Ok((
id.clone(),

View file

@ -74,7 +74,7 @@ impl service::globals::Data for KeyValueDatabase {
.rooms
.state_cache
.rooms_joined(user_id)
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
{
let short_roomid = services()
.rooms
@ -134,7 +134,7 @@ impl service::globals::Data for KeyValueDatabase {
}
fn cleanup(&self) -> Result<()> {
self._db.cleanup()
self.db.cleanup()
}
fn memory_usage(&self) -> String {
@ -158,7 +158,7 @@ our_real_users_cache: {our_real_users_cache}
appservice_in_room_cache: {appservice_in_room_cache}
lasttimelinecount_cache: {lasttimelinecount_cache}\n"
);
if let Ok(db_stats) = self._db.memory_usage() {
if let Ok(db_stats) = self.db.memory_usage() {
response += &db_stats;
}
@ -207,7 +207,7 @@ lasttimelinecount_cache: {lasttimelinecount_cache}\n"
self.global.insert(b"keypair", &keypair)?;
Ok::<_, Error>(keypair)
},
|s| Ok(s.to_vec()),
Ok,
)?;
let mut parts = keypair_bytes.splitn(2, |&b| b == 0xff);

View file

@ -283,7 +283,7 @@ impl service::key_backups::Data for KeyValueDatabase {
Ok::<_, Error>((session_id, key_data))
})
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
.collect())
}

View file

@ -152,21 +152,21 @@ impl service::media::Data for KeyValueDatabase {
value.extend_from_slice(
data.title
.as_ref()
.map(|t| t.as_bytes())
.map(std::string::String::as_bytes)
.unwrap_or_default(),
);
value.push(0xff);
value.extend_from_slice(
data.description
.as_ref()
.map(|d| d.as_bytes())
.map(std::string::String::as_bytes)
.unwrap_or_default(),
);
value.push(0xff);
value.extend_from_slice(
data.image
.as_ref()
.map(|i| i.as_bytes())
.map(std::string::String::as_bytes)
.unwrap_or_default(),
);
value.push(0xff);

View file

@ -15,7 +15,7 @@ impl service::rooms::alias::Data for KeyValueDatabase {
fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> {
if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? {
let mut prefix = room_id.to_vec();
let mut prefix = room_id;
prefix.push(0xff);
for (key, _) in self.aliasid_alias.scan_prefix(prefix) {

View file

@ -76,7 +76,7 @@ impl service::rooms::edus::typing::Data for KeyValueDatabase {
.map_err(|_| Error::bad_database("RoomTyping has invalid timestamp bytes."))?,
))
})
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
.take_while(|&(_, timestamp)| timestamp < current_timestamp)
{
// This is an outdated edu (time > timestamp)

View file

@ -4,11 +4,8 @@ use ruma::{EventId, RoomId, UserId};
use crate::{
database::KeyValueDatabase,
service::{
self,
rooms::timeline::{data::PduData, PduCount},
},
services, utils, Error, Result,
service::{self, rooms::timeline::PduCount},
services, utils, Error, PduEvent, Result,
};
impl service::rooms::pdu_metadata::Data for KeyValueDatabase {
@ -25,7 +22,7 @@ impl service::rooms::pdu_metadata::Data for KeyValueDatabase {
shortroomid: u64,
target: u64,
until: PduCount,
) -> PduData<'a> {
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>> {
let prefix = target.to_be_bytes().to_vec();
let mut current = prefix.clone();

View file

@ -46,13 +46,13 @@ impl service::rooms::short::Data for KeyValueDatabase {
return Ok(Some(*short));
}
let mut statekey = event_type.to_string().as_bytes().to_vec();
statekey.push(0xff);
statekey.extend_from_slice(state_key.as_bytes());
let mut statekey_vec = event_type.to_string().as_bytes().to_vec();
statekey_vec.push(0xff);
statekey_vec.extend_from_slice(state_key.as_bytes());
let short = self
.statekey_shortstatekey
.get(&statekey)?
.get(&statekey_vec)?
.map(|shortstatekey| {
utils::u64_from_bytes(&shortstatekey)
.map_err(|_| Error::bad_database("Invalid shortstatekey in db."))
@ -83,19 +83,19 @@ impl service::rooms::short::Data for KeyValueDatabase {
return Ok(*short);
}
let mut statekey = event_type.to_string().as_bytes().to_vec();
statekey.push(0xff);
statekey.extend_from_slice(state_key.as_bytes());
let mut statekey_vec = event_type.to_string().as_bytes().to_vec();
statekey_vec.push(0xff);
statekey_vec.extend_from_slice(state_key.as_bytes());
let short = match self.statekey_shortstatekey.get(&statekey)? {
let short = match self.statekey_shortstatekey.get(&statekey_vec)? {
Some(shortstatekey) => utils::u64_from_bytes(&shortstatekey)
.map_err(|_| Error::bad_database("Invalid shortstatekey in db."))?,
None => {
let shortstatekey = services().globals.next_count()?;
self.statekey_shortstatekey
.insert(&statekey, &shortstatekey.to_be_bytes())?;
.insert(&statekey_vec, &shortstatekey.to_be_bytes())?;
self.shortstatekey_statekey
.insert(&shortstatekey.to_be_bytes(), &statekey)?;
.insert(&shortstatekey.to_be_bytes(), &statekey_vec)?;
shortstatekey
}
};

View file

@ -63,7 +63,7 @@ impl service::rooms::state::Data for KeyValueDatabase {
}
for event_id in event_ids {
let mut key = prefix.to_owned();
let mut key = prefix.clone();
key.extend_from_slice(event_id.as_bytes());
self.roomid_pduleaves.insert(&key, event_id.as_bytes())?;
}

View file

@ -105,7 +105,10 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
let mut joined_servers = HashSet::new();
let mut real_users = HashSet::new();
for joined in self.room_members(room_id).filter_map(|r| r.ok()) {
for joined in self
.room_members(room_id)
.filter_map(std::result::Result::ok)
{
joined_servers.insert(joined.server_name().to_owned());
if joined.server_name() == services().globals.server_name()
&& !services().users.is_deactivated(&joined).unwrap_or(true)
@ -115,7 +118,10 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
joinedcount += 1;
}
for _invited in self.room_members_invited(room_id).filter_map(|r| r.ok()) {
for _invited in self
.room_members_invited(room_id)
.filter_map(std::result::Result::ok)
{
invitedcount += 1;
}
@ -130,7 +136,10 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
.unwrap()
.insert(room_id.to_owned(), Arc::new(real_users));
for old_joined_server in self.room_servers(room_id).filter_map(|r| r.ok()) {
for old_joined_server in self
.room_servers(room_id)
.filter_map(std::result::Result::ok)
{
if !joined_servers.remove(&old_joined_server) {
// Server not in room anymore
let mut roomserver_id = room_id.as_bytes().to_vec();

View file

@ -70,7 +70,7 @@ impl service::rooms::threads::Data for KeyValueDatabase {
})?)
.map_err(|_| Error::bad_database("Invalid UserId in threadid_userids."))
})
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
.collect(),
))
} else {

View file

@ -5,11 +5,7 @@ use ruma::{
};
use tracing::error;
use crate::{
database::KeyValueDatabase,
service::{self, rooms::timeline::data::PduData},
services, utils, Error, PduEvent, Result,
};
use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result};
use service::rooms::timeline::PduCount;
@ -232,7 +228,7 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
user_id: &UserId,
room_id: &RoomId,
until: PduCount,
) -> PduData<'a> {
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>> {
let (prefix, current) = count_to_id(room_id, until, 1, true)?;
let user_id = user_id.to_owned();
@ -254,7 +250,12 @@ impl service::rooms::timeline::Data for KeyValueDatabase {
))
}
fn pdus_after<'a>(&'a self, user_id: &UserId, room_id: &RoomId, from: PduCount) -> PduData<'a> {
fn pdus_after<'a>(
&'a self,
user_id: &UserId,
room_id: &RoomId,
from: PduCount,
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>> {
let (prefix, current) = count_to_id(room_id, from, 1, false)?;
let user_id = user_id.to_owned();

View file

@ -131,7 +131,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
Ok::<_, Error>(room_id)
})
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
});
// We use the default compare function because keys are sorted correctly (not reversed)

View file

@ -67,9 +67,9 @@ impl service::sending::Data for KeyValueDatabase {
for (outgoing_kind, event) in requests {
let mut key = outgoing_kind.get_prefix();
if let SendingEventType::Pdu(value) = &event {
key.extend_from_slice(value)
key.extend_from_slice(value);
} else {
key.extend_from_slice(&services().globals.next_count()?.to_be_bytes())
key.extend_from_slice(&services().globals.next_count()?.to_be_bytes());
}
let value = if let SendingEventType::Edu(value) = &event {
&**value

View file

@ -12,7 +12,7 @@ impl service::transaction_ids::Data for KeyValueDatabase {
) -> Result<()> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(device_id.map(|d| d.as_bytes()).unwrap_or_default());
key.extend_from_slice(device_id.map(DeviceId::as_bytes).unwrap_or_default());
key.push(0xff);
key.extend_from_slice(txn_id.as_bytes());
@ -29,7 +29,7 @@ impl service::transaction_ids::Data for KeyValueDatabase {
) -> Result<Option<Vec<u8>>> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(device_id.map(|d| d.as_bytes()).unwrap_or_default());
key.extend_from_slice(device_id.map(DeviceId::as_bytes).unwrap_or_default());
key.push(0xff);
key.extend_from_slice(txn_id.as_bytes());

View file

@ -34,7 +34,7 @@ impl service::uiaa::Data for KeyValueDatabase {
.read()
.unwrap()
.get(&(user_id.to_owned(), device_id.to_owned(), session.to_owned()))
.map(|j| j.to_owned())
.map(std::borrow::ToOwned::to_owned)
}
fn update_uiaa_session(

View file

@ -650,7 +650,7 @@ impl service::users::Data for KeyValueDatabase {
.rooms
.state_cache
.rooms_joined(user_id)
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
{
// Don't send key updates to unencrypted rooms
if services()
@ -855,7 +855,7 @@ impl service::users::Data for KeyValueDatabase {
.map_err(|_| Error::bad_database("ToDeviceId has invalid count bytes."))?,
))
})
.filter_map(|r| r.ok())
.filter_map(std::result::Result::ok)
.take_while(|&(_, count)| count <= until)
{
self.todeviceid_events.remove(&key)?;

View file

@ -36,7 +36,7 @@ use tokio::{sync::mpsc, time::interval};
use tracing::{debug, error, info, warn};
pub struct KeyValueDatabase {
_db: Arc<dyn KeyValueDatabaseEngine>,
db: Arc<dyn KeyValueDatabaseEngine>,
//pub globals: globals::Globals,
pub(super) global: Arc<dyn KvTree>,
@ -252,7 +252,7 @@ impl KeyValueDatabase {
let (presence_sender, presence_receiver) = mpsc::unbounded_channel();
let db_raw = Box::new(Self {
_db: builder.clone(),
db: builder.clone(),
userid_password: builder.open_tree("userid_password")?,
userid_displayname: builder.open_tree("userid_displayname")?,
userid_avatarurl: builder.open_tree("userid_avatarurl")?,
@ -616,7 +616,7 @@ impl KeyValueDatabase {
Ok::<_, Error>(())
};
for (k, seventid) in db._db.open_tree("stateid_shorteventid")?.iter() {
for (k, seventid) in db.db.open_tree("stateid_shorteventid")?.iter() {
let sstatehash = utils::u64_from_bytes(&k[0..size_of::<u64>()])
.expect("number of bytes is correct");
let sstatekey = k[size_of::<u64>()..].to_vec();
@ -789,7 +789,7 @@ impl KeyValueDatabase {
}
// Force E2EE device list updates so we can send them over federation
for user_id in services().users.iter().filter_map(|r| r.ok()) {
for user_id in services().users.iter().filter_map(std::result::Result::ok) {
services().users.mark_device_key_update(&user_id)?;
}
@ -799,7 +799,7 @@ impl KeyValueDatabase {
}
if services().globals.database_version()? < 11 {
db._db
db.db
.open_tree("userdevicesessionid_uiaarequest")?
.clear()?;
services().globals.bump_database_version(11)?;
@ -974,7 +974,7 @@ impl KeyValueDatabase {
.into_iter()
.map(|x| &patterns.patterns()[x])
.join(", ")
)
);
}
}
}
@ -998,7 +998,7 @@ impl KeyValueDatabase {
.into_iter()
.map(|x| &patterns.patterns()[x])
.join(", ")
)
);
}
}
}
@ -1039,7 +1039,7 @@ impl KeyValueDatabase {
error!(
"Could not set the configured emergency password for the conduit user: {}",
e
)
);
}
};
@ -1059,7 +1059,7 @@ impl KeyValueDatabase {
pub fn flush(&self) -> Result<()> {
let start = std::time::Instant::now();
let res = self._db.flush();
let res = self.db.flush();
debug!("flush: took {:?}", start.elapsed());
@ -1113,7 +1113,7 @@ impl KeyValueDatabase {
.send_message(RoomMessageEventContent::text_plain(format!(
"@room: the following is a message from the conduwuit puppy. it was sent on '{}':\n\n{}",
update.date, update.message
)))
)));
}
}
services()