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,15 +154,26 @@ impl MerchantConnectorAccountInterface for Store {
merchant_id: &str,
merchant_connector_id: &str,
) -> CustomResult<storage::MerchantConnectorAccount, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await;
storage::MerchantConnectorAccount::find_by_merchant_id_merchant_connector_id(
&conn,
merchant_id,
merchant_connector_id,
)
.await
.map_err(Into::into)
.into_report()
let find_call = || async {
let conn = pg_connection(&self.master_pool).await;
storage::MerchantConnectorAccount::find_by_merchant_id_merchant_connector_id(
&conn,
merchant_id,
merchant_connector_id,
)
.await
.map_err(Into::into)
.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(
@ -189,11 +200,24 @@ impl MerchantConnectorAccountInterface for Store {
this: storage::MerchantConnectorAccount,
merchant_connector_account: storage::MerchantConnectorAccountUpdate,
) -> CustomResult<storage::MerchantConnectorAccount, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await;
this.update(&conn, merchant_connector_account)
.await
.map_err(Into::into)
.into_report()
let _merchant_connector_id = this.merchant_connector_id.clone();
let update_call = || async {
let conn = pg_connection(&self.master_pool).await;
this.update(&conn, merchant_connector_account)
.await
.map_err(Into::into)
.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(

View File

@ -3,7 +3,17 @@ use masking::Secret;
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)]
pub struct MerchantConnectorAccount {
pub id: i32,