Reduced the amount of filters by using find_by_id

This commit is contained in:
StNicolay 2023-05-14 13:59:42 +03:00
parent 2c69882b13
commit e973116df4
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 2 additions and 5 deletions

View File

@ -141,9 +141,7 @@ impl Entity {
account_name: impl Into<String>,
db: &DatabaseConnection,
) -> crate::Result<Option<Model>> {
Self::find()
.filter(Column::UserId.eq(user_id))
.filter(Column::Name.eq(account_name.into()))
Self::find_by_id((user_id, account_name.into()))
.one(db)
.await
.map_err(Into::into)

View File

@ -62,10 +62,9 @@ impl Entity {
/// Checks if the master password for the user exists
pub async fn exists(user_id: u64, db: &DatabaseConnection) -> crate::Result<bool> {
let id = Self::find()
let id = Self::find_by_id(user_id)
.select_only()
.column(Column::UserId)
.filter(Column::UserId.eq(user_id))
.into_tuple::<u64>()
.one(db)
.await?;