mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat(router): add total count for payments list (#1912)
This commit is contained in:
@ -262,6 +262,28 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
|
||||
MerchantStorageScheme::RedisKv => Err(StorageError::KVError.into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
async fn get_filtered_active_attempt_ids_for_total_count(
|
||||
&self,
|
||||
merchant_id: &str,
|
||||
constraints: &PaymentIntentFetchConstraints,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<Vec<String>, StorageError> {
|
||||
match storage_scheme {
|
||||
MerchantStorageScheme::PostgresOnly => {
|
||||
self.router_store
|
||||
.get_filtered_active_attempt_ids_for_total_count(
|
||||
merchant_id,
|
||||
constraints,
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
MerchantStorageScheme::RedisKv => Err(StorageError::KVError.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -454,6 +476,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
.filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))
|
||||
.order(pi_dsl::created_at.desc())
|
||||
.into_boxed();
|
||||
|
||||
query = match constraints {
|
||||
PaymentIntentFetchConstraints::Single { payment_intent_id } => {
|
||||
query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()))
|
||||
@ -568,6 +591,74 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
|
||||
})
|
||||
.attach_printable("Error filtering payment records")
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
async fn get_filtered_active_attempt_ids_for_total_count(
|
||||
&self,
|
||||
merchant_id: &str,
|
||||
constraints: &PaymentIntentFetchConstraints,
|
||||
_storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<Vec<String>, StorageError> {
|
||||
let conn = self.get_replica_pool();
|
||||
|
||||
let mut query = DieselPaymentIntent::table()
|
||||
.select(pi_dsl::active_attempt_id)
|
||||
.filter(pi_dsl::merchant_id.eq(merchant_id.to_owned()))
|
||||
.order(pi_dsl::created_at.desc())
|
||||
.into_boxed();
|
||||
|
||||
query = match constraints {
|
||||
PaymentIntentFetchConstraints::Single { payment_intent_id } => {
|
||||
query.filter(pi_dsl::payment_id.eq(payment_intent_id.to_owned()))
|
||||
}
|
||||
PaymentIntentFetchConstraints::List {
|
||||
starting_at,
|
||||
ending_at,
|
||||
currency,
|
||||
status,
|
||||
customer_id,
|
||||
..
|
||||
} => {
|
||||
if let Some(customer_id) = customer_id {
|
||||
query = query.filter(pi_dsl::customer_id.eq(customer_id.clone()));
|
||||
}
|
||||
|
||||
query = match starting_at {
|
||||
Some(starting_at) => query.filter(pi_dsl::created_at.ge(*starting_at)),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match ending_at {
|
||||
Some(ending_at) => query.filter(pi_dsl::created_at.le(*ending_at)),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match currency {
|
||||
Some(currency) => query.filter(pi_dsl::currency.eq_any(currency.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query = match status {
|
||||
Some(status) => query.filter(pi_dsl::status.eq_any(status.clone())),
|
||||
None => query,
|
||||
};
|
||||
|
||||
query
|
||||
}
|
||||
};
|
||||
|
||||
db_metrics::track_database_call::<<DieselPaymentIntent as HasTable>::Table, _, _>(
|
||||
query.get_results_async::<String>(conn),
|
||||
db_metrics::DatabaseOperation::Filter,
|
||||
)
|
||||
.await
|
||||
.into_report()
|
||||
.map_err(|er| {
|
||||
let new_err = StorageError::DatabaseError(format!("{er:?}"));
|
||||
er.change_context(new_err)
|
||||
})
|
||||
.attach_printable_lazy(|| "Error filtering records by predicate")
|
||||
}
|
||||
}
|
||||
|
||||
impl DataModelExt for PaymentIntentNew {
|
||||
|
||||
Reference in New Issue
Block a user