Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes clippy issues in dbm.rs #251

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading