Skip to content

Commit

Permalink
feat(router): remove unnecessary lookups in refund and payment_attemp…
Browse files Browse the repository at this point in the history
…t kv flow (#2425)
  • Loading branch information
sai-harsha-vardhan authored Oct 4, 2023
1 parent 04f2e11 commit f720aec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 3 additions & 8 deletions crates/router/src/db/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)?;

Expand Down
7 changes: 3 additions & 4 deletions crates/storage_impl/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f720aec

Please sign in to comment.