Skip to content

Commit

Permalink
fix(router): fix refunds and payment_attempts kv flow (#2362)
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-harsha-vardhan authored Sep 26, 2023
1 parent 3d7e22a commit ef0df71
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
6 changes: 1 addition & 5 deletions crates/router/src/db/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,9 @@ mod storage {
}
enums::MerchantStorageScheme::RedisKv => {
let key = format!("{merchant_id}_{payment_id}");
let lookup = self.get_lookup_by_lookup_id(&key).await?;

let pattern = db_utils::generate_hscan_pattern_for_refund(&lookup.sk_id);

self.get_redis_conn()
.map_err(Into::<errors::StorageError>::into)?
.hscan_and_deserialize(&key, &pattern, None)
.hscan_and_deserialize(&key, "pa_*_ref_*", None)
.await
.change_context(errors::StorageError::KVError)
}
Expand Down
10 changes: 2 additions & 8 deletions crates/storage_impl/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use crate::{
diesel_error_to_data_error,
lookup::ReverseLookupInterface,
redis::kv_store::{PartitionKey, RedisConnInterface},
utils::{
generate_hscan_pattern_for_attempt, pg_connection_read, pg_connection_write,
try_redis_get_else_try_database_get,
},
utils::{pg_connection_read, pg_connection_write, try_redis_get_else_try_database_get},
DataModelExt, DatabaseStore, KVRouterStore, RouterStore,
};

Expand Down Expand Up @@ -800,16 +797,13 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
}
MerchantStorageScheme::RedisKv => {
let key = format!("{merchant_id}_{payment_id}");
let lookup = self.get_lookup_by_lookup_id(&key).await?;

let pattern = generate_hscan_pattern_for_attempt(&lookup.sk_id);

self.get_redis_conn()
.map_err(|er| {
let error = format!("{}", er);
er.change_context(errors::StorageError::RedisError(error))
})?
.hscan_and_deserialize(&key, &pattern, None)
.hscan_and_deserialize(&key, "pa_*", None)
.await
.change_context(errors::StorageError::KVError)
}
Expand Down
10 changes: 0 additions & 10 deletions crates/storage_impl/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,3 @@ where
},
}
}

/// Generates hscan field pattern. Suppose the field is pa_1234 it will generate
/// pa_*
pub fn generate_hscan_pattern_for_attempt(sk: &str) -> String {
sk.split('_')
.take(1)
.chain(["*"])
.collect::<Vec<&str>>()
.join("_")
}

0 comments on commit ef0df71

Please sign in to comment.