From fde3372bcc49c980afed173f41f04d5b3ec7976b Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 25 Jun 2024 04:05:23 +0200 Subject: [PATCH] feat: anyquery uses count for faster checks --- upub/core/src/ext.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/upub/core/src/ext.rs b/upub/core/src/ext.rs index bd2f78f..b08651f 100644 --- a/upub/core/src/ext.rs +++ b/upub/core/src/ext.rs @@ -1,4 +1,4 @@ -use sea_orm::ConnectionTrait; +use sea_orm::{ConnectionTrait, PaginatorTrait}; #[async_trait::async_trait] @@ -7,16 +7,19 @@ pub trait AnyQuery { } #[async_trait::async_trait] -impl AnyQuery for sea_orm::Select { +impl AnyQuery for sea_orm::Select +where + T::Model : Sync, +{ async fn any(self, db: &impl ConnectionTrait) -> Result { - Ok(self.one(db).await?.is_some()) + Ok(self.count(db).await? > 0) } } #[async_trait::async_trait] -impl AnyQuery for sea_orm::Selector { +impl AnyQuery for sea_orm::Selector { async fn any(self, db: &impl ConnectionTrait) -> Result { - Ok(self.one(db).await?.is_some()) + Ok(self.count(db).await? > 0) } }