feat: Impelement redis cache for MCA fetch and update (#515)

This commit is contained in:
Kartikeya Hegde
2023-02-10 13:16:41 +05:30
committed by GitHub
parent c7b9e9c1b0
commit 963cb528f5
2 changed files with 49 additions and 15 deletions

View File

@ -154,6 +154,7 @@ impl MerchantConnectorAccountInterface for Store {
merchant_id: &str, merchant_id: &str,
merchant_connector_id: &str, merchant_connector_id: &str,
) -> CustomResult<storage::MerchantConnectorAccount, errors::StorageError> { ) -> CustomResult<storage::MerchantConnectorAccount, errors::StorageError> {
let find_call = || async {
let conn = pg_connection(&self.master_pool).await; let conn = pg_connection(&self.master_pool).await;
storage::MerchantConnectorAccount::find_by_merchant_id_merchant_connector_id( storage::MerchantConnectorAccount::find_by_merchant_id_merchant_connector_id(
&conn, &conn,
@ -163,6 +164,16 @@ impl MerchantConnectorAccountInterface for Store {
.await .await
.map_err(Into::into) .map_err(Into::into)
.into_report() .into_report()
};
#[cfg(not(feature = "accounts_cache"))]
{
find_call().await
}
#[cfg(feature = "accounts_cache")]
{
super::cache::get_or_populate_cache(self, merchant_connector_id, find_call).await
}
} }
async fn insert_merchant_connector_account( async fn insert_merchant_connector_account(
@ -189,11 +200,24 @@ impl MerchantConnectorAccountInterface for Store {
this: storage::MerchantConnectorAccount, this: storage::MerchantConnectorAccount,
merchant_connector_account: storage::MerchantConnectorAccountUpdate, merchant_connector_account: storage::MerchantConnectorAccountUpdate,
) -> CustomResult<storage::MerchantConnectorAccount, errors::StorageError> { ) -> CustomResult<storage::MerchantConnectorAccount, errors::StorageError> {
let _merchant_connector_id = this.merchant_connector_id.clone();
let update_call = || async {
let conn = pg_connection(&self.master_pool).await; let conn = pg_connection(&self.master_pool).await;
this.update(&conn, merchant_connector_account) this.update(&conn, merchant_connector_account)
.await .await
.map_err(Into::into) .map_err(Into::into)
.into_report() .into_report()
};
#[cfg(feature = "accounts_cache")]
{
super::cache::redact_cache(self, &_merchant_connector_id, update_call).await
}
#[cfg(not(feature = "accounts_cache"))]
{
update_call().await
}
} }
async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id(

View File

@ -3,7 +3,17 @@ use masking::Secret;
use crate::{enums as storage_enums, schema::merchant_connector_account}; use crate::{enums as storage_enums, schema::merchant_connector_account};
#[derive(Clone, Debug, Eq, PartialEq, Identifiable, Queryable, router_derive::DebugAsDisplay)] #[derive(
Clone,
Debug,
Eq,
serde::Serialize,
serde::Deserialize,
PartialEq,
Identifiable,
Queryable,
router_derive::DebugAsDisplay,
)]
#[diesel(table_name = merchant_connector_account)] #[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccount { pub struct MerchantConnectorAccount {
pub id: i32, pub id: i32,