Skip to content

Commit

Permalink
Fixes clippy issues in dbm.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-gi committed Mar 28, 2024
1 parent 7ea92bb commit 52ebbe6
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions teos/src/dbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl DBM {
}

/// Removes some users from the database in batch.
pub(crate) fn batch_remove_users(&mut self, users: &Vec<UserId>) -> usize {
pub(crate) fn batch_remove_users(&mut self, users: &[UserId]) -> usize {
let limit = self.connection.limit(Limit::SQLITE_LIMIT_VARIABLE_NUMBER) as usize;
let tx = self.connection.transaction().unwrap();
let iter = users
Expand Down Expand Up @@ -417,7 +417,7 @@ impl DBM {
/// update is atomic.
pub(crate) fn batch_remove_appointments(
&mut self,
appointments: &Vec<UUID>,
appointments: &[UUID],
updated_users: &HashMap<UserId, UserInfo>,
) -> usize {
let limit = self.connection.limit(Limit::SQLITE_LIMIT_VARIABLE_NUMBER) as usize;
Expand Down Expand Up @@ -935,7 +935,7 @@ mod tests {
Ok { .. }
));

dbm.batch_remove_users(&vec![appointment.user_id]);
dbm.batch_remove_users(&[appointment.user_id]);
assert!(dbm.load_user(appointment.user_id).is_none());
assert!(dbm.load_appointment(uuid).is_none());

Expand All @@ -947,7 +947,7 @@ mod tests {
));
assert!(matches!(dbm.store_tracker(uuid, &tracker), Ok { .. }));

dbm.batch_remove_users(&vec![appointment.user_id]);
dbm.batch_remove_users(&[appointment.user_id]);
assert!(dbm.load_user(appointment.user_id).is_none());
assert!(dbm.load_appointment(uuid).is_none());
assert!(dbm.load_tracker(uuid).is_none());
Expand All @@ -956,7 +956,7 @@ mod tests {
#[test]
fn test_batch_remove_nonexistent_users() {
let mut dbm = DBM::in_memory().unwrap();
let users = (0..10).map(|_| get_random_user_id()).collect();
let users = (0..10).map(|_| get_random_user_id()).collect::<Vec<_>>();

// Test it does not fail even if the user does not exist (it will log though)
dbm.batch_remove_users(&users);
Expand Down Expand Up @@ -1286,10 +1286,7 @@ mod tests {
Ok { .. }
));

dbm.batch_remove_appointments(
&vec![uuid],
&HashMap::from_iter([(appointment.user_id, info)]),
);
dbm.batch_remove_appointments(&[uuid], &HashMap::from_iter([(appointment.user_id, info)]));
assert!(dbm.load_appointment(uuid).is_none());

// Appointment + Tracker
Expand All @@ -1299,18 +1296,15 @@ mod tests {
));
assert!(matches!(dbm.store_tracker(uuid, &tracker), Ok { .. }));

dbm.batch_remove_appointments(
&vec![uuid],
&HashMap::from_iter([(appointment.user_id, info)]),
);
dbm.batch_remove_appointments(&[uuid], &HashMap::from_iter([(appointment.user_id, info)]));
assert!(dbm.load_appointment(uuid).is_none());
assert!(dbm.load_tracker(uuid).is_none());
}

#[test]
fn test_batch_remove_nonexistent_appointments() {
let mut dbm = DBM::in_memory().unwrap();
let appointments = (0..10).map(|_| generate_uuid()).collect();
let appointments = (0..10).map(|_| generate_uuid()).collect::<Vec<_>>();

// Test it does not fail even if the user does not exist (it will log though)
dbm.batch_remove_appointments(&appointments, &HashMap::new());
Expand Down

0 comments on commit 52ebbe6

Please sign in to comment.