Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): remove unnecessary lookups in refund and payment_attempt kv flow (#2425)
Sai Harsha Vardhanf720aecf1fb6
diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rsindex 67980730f8..93227d7184 100644--- a/crates/router/src/db/refund.rs+++ b/crates/router/src/db/refund.rs@@ -498,14 +498,9 @@ mod storage {.into_report()}enums::MerchantStorageScheme::RedisKv => {- let key = format!("{}_{}", this.merchant_id, this.refund_id);-+ let key = format!("{}_{}", this.merchant_id, this.payment_id);+ let field = format!("pa_{}_ref_{}", &this.attempt_id, &this.refund_id);let updated_refund = refund.clone().apply_changeset(this.clone());- // Check for database presence as well Maybe use a read replica here ?-- let lookup = self.get_lookup_by_lookup_id(&key).await?;-- let field = &lookup.sk_id;let redis_value =utils::Encode::<storage_types::Refund>::encode_to_string_of_json(@@ -515,7 +510,7 @@ mod storage {self.get_redis_conn().map_err(Into::<errors::StorageError>::into)?- .set_hash_fields(&lookup.pk_id, (field, redis_value))+ .set_hash_fields(&key, (field, redis_value)).await.change_context(errors::StorageError::KVError)?;diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rsindex 693772e89b..954da5d8c0 100644--- a/crates/storage_impl/src/payments/payment_attempt.rs+++ b/crates/storage_impl/src/payments/payment_attempt.rs@@ -669,16 +669,15 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {.await}MerchantStorageScheme::RedisKv => {- let lookup_id = format!("{merchant_id}_{attempt_id}");- let lookup = self.get_lookup_by_lookup_id(&lookup_id).await?;- let key = &lookup.pk_id;+ let key = format!("{merchant_id}_{payment_id}");+ let field = format!("pa_{attempt_id}");try_redis_get_else_try_database_get(self.get_redis_conn().map_err(|er| {let error = format!("{}", er);er.change_context(errors::StorageError::RedisError(error))})?- .get_hash_field_and_deserialize(key, &lookup.sk_id, "PaymentAttempt"),+ .get_hash_field_and_deserialize(&key, &field, "PaymentAttempt"),|| async {self.router_store.find_payment_attempt_by_payment_id_merchant_id_attempt_id(