chore: remove redundant caching code (#4804)

This commit is contained in:
Sanchith Hegde
2024-05-30 13:06:52 +05:30
committed by GitHub
parent d790f8f361
commit 971ef1fb8f
17 changed files with 149 additions and 283 deletions

View File

@ -1,18 +1,21 @@
use common_utils::errors::CustomResult;
use error_stack::{report, ResultExt};
use storage_impl::redis::cache::CacheKind;
use storage_impl::redis::cache::{publish_into_redact_channel, CacheKind};
use super::errors;
use crate::{db::cache::publish_into_redact_channel, routes::AppState, services};
use crate::{routes::AppState, services};
pub async fn invalidate(
state: AppState,
key: &str,
) -> CustomResult<services::api::ApplicationResponse<serde_json::Value>, errors::ApiErrorResponse> {
let store = state.store.as_ref();
let result = publish_into_redact_channel(store, [CacheKind::All(key.into())])
.await
.change_context(errors::ApiErrorResponse::InternalServerError)?;
let result = publish_into_redact_channel(
store.get_cache_store().as_ref(),
[CacheKind::All(key.into())],
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)?;
// If the message was published to atleast one channel
// then return status Ok

View File

@ -13,27 +13,26 @@ use euclid::{
};
use router_env::{instrument, tracing};
use crate::{
core::payments::{types, PaymentData},
db::StorageInterface,
types::{
storage::{self as oss_storage, payment_attempt::PaymentAttemptExt},
transformers::ForeignTryFrom,
},
};
static CONF_CACHE: StaticCache<VirInterpreterBackendCacheWrapper> = StaticCache::new();
use crate::{
core::{
errors::ConditionalConfigError as ConfigError,
payments::{
conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge,
types, PaymentData,
},
},
db::StorageInterface,
types::{
storage::{self, payment_attempt::PaymentAttemptExt},
transformers::ForeignTryFrom,
},
AppState,
};
static CONF_CACHE: StaticCache<VirInterpreterBackendCacheWrapper> = StaticCache::new();
struct VirInterpreterBackendCacheWrapper {
cached_alogorith: backend::VirInterpreterBackend<SurchargeDecisionConfigs>,
cached_algorithm: backend::VirInterpreterBackend<SurchargeDecisionConfigs>,
merchant_surcharge_configs: surcharge_decision_configs::MerchantSurchargeConfigs,
}
@ -41,12 +40,12 @@ impl TryFrom<SurchargeDecisionManagerRecord> for VirInterpreterBackendCacheWrapp
type Error = error_stack::Report<ConfigError>;
fn try_from(value: SurchargeDecisionManagerRecord) -> Result<Self, Self::Error> {
let cached_alogorith = backend::VirInterpreterBackend::with_program(value.algorithm)
let cached_algorithm = backend::VirInterpreterBackend::with_program(value.algorithm)
.change_context(ConfigError::DslBackendInitError)
.attach_printable("Error initializing DSL interpreter backend")?;
let merchant_surcharge_configs = value.merchant_surcharge_configs;
Ok(Self {
cached_alogorith,
cached_algorithm,
merchant_surcharge_configs,
})
}
@ -63,14 +62,14 @@ impl SurchargeSource {
pub fn generate_surcharge_details_and_populate_surcharge_metadata(
&self,
backend_input: &backend::BackendInput,
payment_attempt: &oss_storage::PaymentAttempt,
payment_attempt: &storage::PaymentAttempt,
surcharge_metadata_and_key: (&mut types::SurchargeMetadata, types::SurchargeKey),
) -> ConditionalConfigResult<Option<types::SurchargeDetails>> {
match self {
Self::Generate(interpreter) => {
let surcharge_output = execute_dsl_and_get_conditional_config(
backend_input.clone(),
&interpreter.cached_alogorith,
&interpreter.cached_algorithm,
)?;
Ok(surcharge_output
.surcharge_details
@ -98,8 +97,8 @@ impl SurchargeSource {
pub async fn perform_surcharge_decision_management_for_payment_method_list(
state: &AppState,
algorithm_ref: routing::RoutingAlgorithmRef,
payment_attempt: &oss_storage::PaymentAttempt,
payment_intent: &oss_storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
billing_address: Option<payments::Address>,
response_payment_method_types: &mut [api_models::payment_methods::ResponsePaymentMethodsEnabled],
) -> ConditionalConfigResult<(
@ -279,8 +278,8 @@ where
pub async fn perform_surcharge_decision_management_for_saved_cards(
state: &AppState,
algorithm_ref: routing::RoutingAlgorithmRef,
payment_attempt: &oss_storage::PaymentAttempt,
payment_intent: &oss_storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
customer_payment_method_list: &mut [api_models::payment_methods::CustomerPaymentMethod],
) -> ConditionalConfigResult<types::SurchargeMetadata> {
let mut surcharge_metadata = types::SurchargeMetadata::new(payment_attempt.attempt_id.clone());
@ -348,7 +347,7 @@ pub async fn perform_surcharge_decision_management_for_saved_cards(
fn get_surcharge_details_from_surcharge_output(
surcharge_details: surcharge_decision_configs::SurchargeDetailsOutput,
payment_attempt: &oss_storage::PaymentAttempt,
payment_attempt: &storage::PaymentAttempt,
) -> ConditionalConfigResult<types::SurchargeDetails> {
let surcharge_amount = match surcharge_details.surcharge.clone() {
surcharge_decision_configs::SurchargeOutput::Fixed { amount } => amount,

View File

@ -10,11 +10,11 @@ use diesel_models::{
};
use error_stack::ResultExt;
use rustc_hash::FxHashSet;
use storage_impl::redis::cache as redis_cache;
use storage_impl::redis::cache;
use crate::{
core::errors::{self, RouterResult},
db::{cache, StorageInterface},
db::StorageInterface,
types::{domain, storage},
utils::StringExt,
};
@ -245,12 +245,11 @@ pub async fn update_business_profile_active_algorithm_ref(
#[cfg(feature = "business_profile_routing")]
let profile_id = current_business_profile.profile_id.clone();
#[cfg(feature = "business_profile_routing")]
let routing_cache_key = redis_cache::CacheKind::Routing(
format!("routing_config_{merchant_id}_{profile_id}").into(),
);
let routing_cache_key =
cache::CacheKind::Routing(format!("routing_config_{merchant_id}_{profile_id}").into());
#[cfg(not(feature = "business_profile_routing"))]
let routing_cache_key = redis_cache::CacheKind::Routing(format!("dsl_{merchant_id}").into());
let routing_cache_key = cache::CacheKind::Routing(format!("dsl_{merchant_id}").into());
let (routing_algorithm, payout_routing_algorithm) = match transaction_type {
storage::enums::TransactionType::Payment => (Some(ref_val), None),
#[cfg(feature = "payouts")]
@ -285,7 +284,7 @@ pub async fn update_business_profile_active_algorithm_ref(
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to update routing algorithm ref in business profile")?;
cache::publish_into_redact_channel(db, [routing_cache_key])
cache::publish_into_redact_channel(db.get_cache_store().as_ref(), [routing_cache_key])
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to invalidate routing cache")?;