Fix a bunch of clippy lints

This commit is contained in:
Jonas Platte 2021-08-31 21:20:03 +02:00 committed by Jonas Zohren
parent 4cba464faf
commit e14db60b6c
8 changed files with 77 additions and 85 deletions

View file

@ -251,8 +251,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map_err(|_| { .map_err(|_| {
Error::bad_database("Invalid room name event in database.") Error::bad_database("Invalid room name event in database.")
})? })?
.name .name)
.map(|n| n.to_owned().into()))
})?, })?,
num_joined_members: db num_joined_members: db
.rooms .rooms

View file

@ -37,10 +37,9 @@ pub async fn set_displayname_route(
.set_displayname(&sender_user, body.displayname.clone())?; .set_displayname(&sender_user, body.displayname.clone())?;
// Send a new membership event and presence update into all joined rooms // Send a new membership event and presence update into all joined rooms
let all_rooms_joined = db.rooms.rooms_joined(&sender_user).collect::<Vec<_>>(); let all_rooms_joined: Vec<_> = db
.rooms
for (pdu_builder, room_id) in all_rooms_joined .rooms_joined(&sender_user)
.into_iter()
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.map(|room_id| { .map(|room_id| {
Ok::<_, Error>(( Ok::<_, Error>((
@ -77,7 +76,9 @@ pub async fn set_displayname_route(
)) ))
}) })
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
{ .collect();
for (pdu_builder, room_id) in all_rooms_joined {
let mutex_state = Arc::clone( let mutex_state = Arc::clone(
db.globals db.globals
.roomid_mutex_state .roomid_mutex_state
@ -181,10 +182,9 @@ pub async fn set_avatar_url_route(
db.users.set_blurhash(&sender_user, body.blurhash.clone())?; db.users.set_blurhash(&sender_user, body.blurhash.clone())?;
// Send a new membership event and presence update into all joined rooms // Send a new membership event and presence update into all joined rooms
let all_joined_rooms = db.rooms.rooms_joined(&sender_user).collect::<Vec<_>>(); let all_joined_rooms: Vec<_> = db
.rooms
for (pdu_builder, room_id) in all_joined_rooms .rooms_joined(&sender_user)
.into_iter()
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.map(|room_id| { .map(|room_id| {
Ok::<_, Error>(( Ok::<_, Error>((
@ -221,7 +221,9 @@ pub async fn set_avatar_url_route(
)) ))
}) })
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
{ .collect();
for (pdu_builder, room_id) in all_joined_rooms {
let mutex_state = Arc::clone( let mutex_state = Arc::clone(
db.globals db.globals
.roomid_mutex_state .roomid_mutex_state

View file

@ -356,7 +356,7 @@ async fn sync_helper(
true, true,
state_events, state_events,
) )
} else if timeline_pdus.len() == 0 && since_shortstatehash == Some(current_shortstatehash) { } else if timeline_pdus.is_empty() && since_shortstatehash == Some(current_shortstatehash) {
// No state changes // No state changes
(Vec::new(), None, None, false, Vec::new()) (Vec::new(), None, None, false, Vec::new())
} else { } else {

View file

@ -655,7 +655,7 @@ impl Database {
if db.globals.database_version()? < 9 { if db.globals.database_version()? < 9 {
// Update tokenids db layout // Update tokenids db layout
let batch = db let mut iter = db
.rooms .rooms
.tokenids .tokenids
.iter() .iter()
@ -683,9 +683,7 @@ impl Database {
println!("new {:?}", new_key); println!("new {:?}", new_key);
Some((new_key, Vec::new())) Some((new_key, Vec::new()))
}) })
.collect::<Vec<_>>(); .peekable();
let mut iter = batch.into_iter().peekable();
while iter.peek().is_some() { while iter.peek().is_some() {
db.rooms db.rooms

View file

@ -65,12 +65,12 @@ impl Engine {
self.writer.lock() self.writer.lock()
} }
fn read_lock<'a>(&'a self) -> &'a Connection { fn read_lock(&self) -> &Connection {
self.read_conn_tls self.read_conn_tls
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap()) .get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
} }
fn read_lock_iterator<'a>(&'a self) -> &'a Connection { fn read_lock_iterator(&self) -> &Connection {
self.read_iterator_conn_tls self.read_iterator_conn_tls
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap()) .get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
} }

View file

@ -40,7 +40,7 @@ impl AccountData {
roomuserdataid.push(0xff); roomuserdataid.push(0xff);
roomuserdataid.extend_from_slice(&event_type.as_bytes()); roomuserdataid.extend_from_slice(&event_type.as_bytes());
let mut key = prefix.clone(); let mut key = prefix;
key.extend_from_slice(event_type.as_bytes()); key.extend_from_slice(event_type.as_bytes());
let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling

View file

@ -385,7 +385,7 @@ impl Rooms {
self.save_state_from_diff( self.save_state_from_diff(
new_shortstatehash, new_shortstatehash,
statediffnew.clone(), statediffnew.clone(),
statediffremoved.clone(), statediffremoved,
2, // every state change is 2 event changes on average 2, // every state change is 2 event changes on average
states_parents, states_parents,
)?; )?;
@ -497,8 +497,7 @@ impl Rooms {
Ok(response) Ok(response)
} else { } else {
let mut response = Vec::new(); let response = vec![(shortstatehash, added.clone(), added, removed)];
response.push((shortstatehash, added.clone(), added, removed));
self.stateinfo_cache self.stateinfo_cache
.lock() .lock()
.unwrap() .unwrap()
@ -609,7 +608,7 @@ impl Rooms {
return Ok(()); return Ok(());
} }
if parent_states.len() == 0 { if parent_states.is_empty() {
// There is no parent layer, create a new state // There is no parent layer, create a new state
let mut value = 0_u64.to_be_bytes().to_vec(); // 0 means no parent let mut value = 0_u64.to_be_bytes().to_vec(); // 0 means no parent
for new in &statediffnew { for new in &statediffnew {
@ -689,7 +688,7 @@ impl Rooms {
state_hash: &StateHashId, state_hash: &StateHashId,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<(u64, bool)> { ) -> Result<(u64, bool)> {
Ok(match self.statehash_shortstatehash.get(&state_hash)? { Ok(match self.statehash_shortstatehash.get(state_hash)? {
Some(shortstatehash) => ( Some(shortstatehash) => (
utils::u64_from_bytes(&shortstatehash) utils::u64_from_bytes(&shortstatehash)
.map_err(|_| Error::bad_database("Invalid shortstatehash in db."))?, .map_err(|_| Error::bad_database("Invalid shortstatehash in db."))?,
@ -698,7 +697,7 @@ impl Rooms {
None => { None => {
let shortstatehash = globals.next_count()?; let shortstatehash = globals.next_count()?;
self.statehash_shortstatehash self.statehash_shortstatehash
.insert(&state_hash, &shortstatehash.to_be_bytes())?; .insert(state_hash, &shortstatehash.to_be_bytes())?;
(shortstatehash, false) (shortstatehash, false)
} }
}) })
@ -1784,8 +1783,8 @@ impl Rooms {
}; };
self.save_state_from_diff( self.save_state_from_diff(
shortstatehash, shortstatehash,
statediffnew.clone(), statediffnew,
statediffremoved.clone(), statediffremoved,
1_000_000, // high number because no state will be based on this one 1_000_000, // high number because no state will be based on this one
states_parents, states_parents,
)?; )?;
@ -1930,15 +1929,14 @@ impl Rooms {
let mut key = shortroomid.to_be_bytes().to_vec(); let mut key = shortroomid.to_be_bytes().to_vec();
key.extend_from_slice(&token.to_be_bytes()); key.extend_from_slice(&token.to_be_bytes());
Ok(self self.roomsynctoken_shortstatehash
.roomsynctoken_shortstatehash
.get(&key)? .get(&key)?
.map(|bytes| { .map(|bytes| {
utils::u64_from_bytes(&bytes).map_err(|_| { utils::u64_from_bytes(&bytes).map_err(|_| {
Error::bad_database("Invalid shortstatehash in roomsynctoken_shortstatehash") Error::bad_database("Invalid shortstatehash in roomsynctoken_shortstatehash")
}) })
}) })
.transpose()?) .transpose()
} }
/// Creates a new persisted data unit and adds it to a room. /// Creates a new persisted data unit and adds it to a room.
@ -2491,8 +2489,8 @@ impl Rooms {
self.roomuserid_leftcount.remove(&roomuser_id)?; self.roomuserid_leftcount.remove(&roomuser_id)?;
} }
member::MembershipState::Leave | member::MembershipState::Ban => { member::MembershipState::Leave | member::MembershipState::Ban => {
if update_joined_count { if update_joined_count
if self && self
.room_members(room_id) .room_members(room_id)
.chain(self.room_members_invited(room_id)) .chain(self.room_members_invited(room_id))
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
@ -2501,7 +2499,6 @@ impl Rooms {
self.roomserverids.remove(&roomserver_id)?; self.roomserverids.remove(&roomserver_id)?;
self.serverroomids.remove(&serverroom_id)?; self.serverroomids.remove(&serverroom_id)?;
} }
}
self.userroomid_leftstate.insert( self.userroomid_leftstate.insert(
&userroom_id, &userroom_id,
&serde_json::to_vec(&Vec::<Raw<AnySyncStateEvent>>::new()).unwrap(), &serde_json::to_vec(&Vec::<Raw<AnySyncStateEvent>>::new()).unwrap(),
@ -2637,8 +2634,7 @@ impl Rooms {
if let Some(b) = maybe { if let Some(b) = maybe {
Ok(b) Ok(b)
} else { } else if let Some(namespaces) = appservice.1.get("namespaces") {
if let Some(namespaces) = appservice.1.get("namespaces") {
let users = namespaces let users = namespaces
.get("users") .get("users")
.and_then(|users| users.as_sequence()) .and_then(|users| users.as_sequence())
@ -2677,7 +2673,6 @@ impl Rooms {
Ok(false) Ok(false)
} }
} }
}
#[tracing::instrument(skip(self, db))] #[tracing::instrument(skip(self, db))]
pub async fn leave_room( pub async fn leave_room(
@ -3477,10 +3472,7 @@ impl Rooms {
} }
// Cache in RAM // Cache in RAM
self.auth_chain_cache self.auth_chain_cache.lock().unwrap().insert(key, chain);
.lock()
.unwrap()
.insert(key.clone(), chain);
Ok(()) Ok(())
} }

View file

@ -147,7 +147,7 @@ where
let result = find_actual_destination(globals, &destination).await; let result = find_actual_destination(globals, &destination).await;
(result.0, result.1.clone().into_uri_string()) (result.0, result.1.into_uri_string())
}; };
let actual_destination_str = actual_destination.clone().into_https_string(); let actual_destination_str = actual_destination.clone().into_https_string();
@ -1562,7 +1562,7 @@ async fn upgrade_outlier_to_timeline_pdu(
None None
}; };
if !state_res::event_auth::auth_check( let check_result = state_res::event_auth::auth_check(
&room_version, &room_version,
&incoming_pdu, &incoming_pdu,
previous_create.clone(), previous_create.clone(),
@ -1576,8 +1576,9 @@ async fn upgrade_outlier_to_timeline_pdu(
.and_then(|event_id| db.rooms.get_pdu(&event_id).ok().flatten()) .and_then(|event_id| db.rooms.get_pdu(&event_id).ok().flatten())
}, },
) )
.map_err(|_e| "Auth check failed.".to_owned())? .map_err(|_e| "Auth check failed.".to_owned())?;
{
if !check_result {
return Err("Event has failed auth check with state at the event.".into()); return Err("Event has failed auth check with state at the event.".into());
} }
debug!("Auth check succeeded."); debug!("Auth check succeeded.");