Skip to content

Commit

Permalink
refactor: replace OR with IN operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed May 18, 2024
1 parent 23589a8 commit 45c3b7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/database/postgres/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ WHERE
DELETE FROM
registered_user_audit
WHERE
(old_values -> 'registered_user_id')::BIGINT = $1
OR (new_values -> 'registered_user_id')::BIGINT = $1";
$1 IN ((old_values -> 'registered_user_id')::BIGINT, (new_values -> 'registered_user_id')::BIGINT)";
sqlx::query(user_audit_query)
.bind(self.registered_user_id.get())
.execute(&mut *transaction)
Expand All @@ -319,8 +318,7 @@ WHERE
DELETE FROM
device_audit
WHERE
(old_values -> 'registered_user_id')::BIGINT = $1
OR (new_values -> 'registered_user_id')::BIGINT = $1";
$1 IN ((old_values -> 'registered_user_id')::BIGINT, (new_values -> 'registered_user_id')::BIGINT)";
sqlx::query(device_audit)
.bind(self.registered_user_id.get())
.execute(&mut *transaction)
Expand All @@ -329,8 +327,7 @@ WHERE
DELETE FROM
api_key_audit
WHERE
(old_values -> 'registered_user_id')::BIGINT = $1
OR (new_values -> 'registered_user_id')::BIGINT = $1";
$1 IN ((old_values -> 'registered_user_id')::BIGINT, (new_values -> 'registered_user_id')::BIGINT)";
sqlx::query(api_key_audit)
.bind(self.registered_user_id.get())
.execute(&mut *transaction)
Expand All @@ -339,8 +336,7 @@ WHERE
DELETE FROM
two_fa_secret_audit
WHERE
(old_values -> 'registered_user_id')::BIGINT = $1
OR (new_values -> 'registered_user_id')::BIGINT = $1";
$1 IN ((old_values -> 'registered_user_id')::BIGINT, (new_values -> 'registered_user_id')::BIGINT)";
sqlx::query(two_fa_secret_audit)
.bind(self.registered_user_id.get())
.execute(&mut *transaction)
Expand All @@ -349,8 +345,7 @@ WHERE
DELETE FROM
two_fa_backup_audit
WHERE
(old_values -> 'registered_user_id')::BIGINT = $1
OR (new_values -> 'registered_user_id')::BIGINT = $1";
$1 IN ((old_values -> 'registered_user_id')::BIGINT, (new_values -> 'registered_user_id')::BIGINT)";
sqlx::query(two_fa_backup_audit)
.bind(self.registered_user_id.get())
.execute(&mut *transaction)
Expand Down
4 changes: 2 additions & 2 deletions src/servers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,15 @@ pub mod test_setup {

/// Remove test user from postgres
pub async fn delete_test_users(&self) {
let query = r"DELETE FROM registered_user WHERE full_name = $1 OR full_name = $2;";
let query = r"DELETE FROM registered_user WHERE full_name IN ($1, $2);";
sqlx::query(query)
.bind(ANON_FULL_NAME)
.bind(TEST_FULL_NAME)
.execute(&self.postgres)
.await
.unwrap();

let query = r"DELETE FROM email_address WHERE email = $1 OR EMAIL = $2;";
let query = r"DELETE FROM email_address WHERE email IN ($1, $2);";
sqlx::query(query)
.bind(TEST_EMAIL)
.bind(ANON_EMAIL)
Expand Down

0 comments on commit 45c3b7d

Please sign in to comment.