refactor(core): add cache redaction for cgraph (#9629)

This commit is contained in:
Prajjwal Kumar
2025-10-01 13:25:45 +05:30
committed by GitHub
parent cba489ffa9
commit 654ffe472f
3 changed files with 40 additions and 1 deletions

View File

@ -23,6 +23,7 @@ use masking::{ExposeInterface, PeekInterface, Secret};
use pm_auth::types as pm_auth_types;
use uuid::Uuid;
use super::routing::helpers::redact_cgraph_cache;
#[cfg(any(feature = "v1", feature = "v2"))]
use crate::types::transformers::ForeignFrom;
use crate::{
@ -2577,6 +2578,9 @@ pub async fn create_connector(
},
)?;
// redact cgraph cache on new connector creation
redact_cgraph_cache(&state, merchant_id, business_profile.get_id()).await?;
#[cfg(feature = "v1")]
disputes::schedule_dispute_sync_task(&state, &business_profile, &mca).await?;
@ -2887,6 +2891,9 @@ pub async fn update_connector(
)
})?;
// redact cgraph cache on connector updation
redact_cgraph_cache(&state, merchant_id, &profile_id).await?;
let response = updated_mca.foreign_try_into()?;
Ok(service_api::ApplicationResponse::Json(response))
@ -2956,6 +2963,8 @@ pub async fn delete_connector(
.retrieve_and_delete_from_default_fallback_routing_algorithm_if_routable_connector_exists()
.await?;
// redact cgraph cache on connector deletion
redact_cgraph_cache(&state, &merchant_id, &mca.profile_id).await?;
let response = api::MerchantConnectorDeleteResponse {
merchant_id,
merchant_connector_id,

View File

@ -2731,3 +2731,33 @@ pub async fn delete_decision_engine_merchant(
Ok(())
}
pub async fn redact_cgraph_cache(
state: &SessionState,
merchant_id: &id_type::MerchantId,
profile_id: &id_type::ProfileId,
) -> RouterResult<()> {
let cgraph_payouts_key = format!(
"cgraph_po_{}_{}",
merchant_id.get_string_repr(),
profile_id.get_string_repr(),
);
let cgraph_payments_key = format!(
"cgraph_{}_{}",
merchant_id.get_string_repr(),
profile_id.get_string_repr(),
);
let config_payouts_key = cache::CacheKind::CGraph(cgraph_payouts_key.clone().into());
let config_payments_key = cache::CacheKind::CGraph(cgraph_payments_key.clone().into());
cache::redact_from_redis_and_publish(
state.store.get_cache_store().as_ref(),
[config_payouts_key, config_payments_key],
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to invalidate the cgraph cache")?;
Ok(())
}

View File

@ -214,7 +214,7 @@ pub struct SubscriptionWithHandler<'a> {
profile: hyperswitch_domain_models::business_profile::Profile,
}
impl<'a> SubscriptionWithHandler<'a> {
impl SubscriptionWithHandler<'_> {
fn generate_response(
&self,
invoice: &diesel_models::invoice::Invoice,