Fix: Refactor upstream count retrieval and improve query filtering logic
This commit is contained in:
@@ -173,7 +173,7 @@ impl UpstreamService for UpstreamServiceImpl {
|
||||
let count_info = with_conn!(&*self.connection, tx, conn, {
|
||||
upstream::Entity::find()
|
||||
.select_only()
|
||||
.column_as(upstream::Column::Id, "count")
|
||||
.column_as(upstream::Column::Id.count(), "count")
|
||||
.into_model::<CountResult>()
|
||||
.one(*conn)
|
||||
.await?
|
||||
@@ -199,9 +199,10 @@ impl UpstreamService for UpstreamServiceImpl {
|
||||
)))?;
|
||||
let targets = upstream_target::Entity::find()
|
||||
.filter(upstream_target::Column::UpstreamId.eq(upstream_id))
|
||||
.apply_if(Some(concrete_options.filter_by_enabled), |query, _v| {
|
||||
query.filter(upstream_target::Column::Enabled.eq(true))
|
||||
})
|
||||
.apply_if(
|
||||
concrete_options.filter_by_enabled.then_some(true),
|
||||
|query, _v| query.filter(upstream_target::Column::Enabled.eq(true)),
|
||||
)
|
||||
.all(*conn)
|
||||
.await?;
|
||||
(up, targets)
|
||||
|
||||
Reference in New Issue
Block a user