Skip to content

Commit

Permalink
Refactor(core): reverts the payment method list filtering using const…
Browse files Browse the repository at this point in the history
…raint graph (#5044)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
prajjwalkumar17 and hyperswitch-bot[bot] committed Jun 19, 2024
1 parent 7d46afd commit e486641
Show file tree
Hide file tree
Showing 8 changed files with 462 additions and 264 deletions.
2 changes: 0 additions & 2 deletions crates/euclid/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ pub enum MandateAcceptanceType {
pub enum PaymentType {
SetupMandate,
NonMandate,
NewMandate,
UpdateMandate,
}

#[derive(
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/core/payment_methods.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod cards;
pub mod surcharge_decision_configs;
pub mod transformers;
pub mod utils;
pub mod vault;

pub use api_models::enums::Connector;
Expand Down
671 changes: 457 additions & 214 deletions crates/router/src/core/payment_methods/cards.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/router/src/core/payment_methods/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{str::FromStr, sync::Arc};

:
use api_models::{
admin::{self, PaymentMethodsEnabled},
enums as api_enums,
Expand Down Expand Up @@ -571,7 +571,7 @@ fn compile_accepted_countries_for_mca(
agg_nodes.push((
pm_object_country_value_node,
cgraph::Relation::Positive,
cgraph::Strength::Weak,
cgraph::Strength::Strong,
));
}
admin::AcceptedCountries::DisableOnly(countries) => {
Expand All @@ -592,7 +592,7 @@ fn compile_accepted_countries_for_mca(
agg_nodes.push((
pm_object_country_value_node,
cgraph::Relation::Positive,
cgraph::Strength::Weak,
cgraph::Strength::Strong,
));
}
admin::AcceptedCountries::AllAccepted => return Ok(None),
Expand Down Expand Up @@ -628,7 +628,7 @@ fn compile_accepted_countries_for_mca(
agg_nodes.push((
config_country_agg_node,
cgraph::Relation::Positive,
cgraph::Strength::Weak,
cgraph::Strength::Strong,
));
}
}
Expand Down
6 changes: 0 additions & 6 deletions crates/router/src/db/merchant_connector_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,6 @@ impl MerchantConnectorAccountInterface for Store {
cache::CacheKind::CGraph(
format!("cgraph_{}_{_profile_id}", _merchant_id).into(),
),
cache::CacheKind::PmFiltersCGraph(
format!("pm_filters_cgraph_{}_{_profile_id}", _merchant_id).into(),
),
],
update_call,
)
Expand Down Expand Up @@ -598,9 +595,6 @@ impl MerchantConnectorAccountInterface for Store {
cache::CacheKind::CGraph(
format!("cgraph_{}_{_profile_id}", mca.merchant_id).into(),
),
cache::CacheKind::PmFiltersCGraph(
format!("pm_filters_cgraph_{}_{_profile_id}", mca.merchant_id).into(),
),
],
delete_call,
)
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/routes/metrics/bg_metrics_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub fn spawn_metrics_collector(metrics_collection_interval_in_secs: &Option<u16>
&cache::ACCOUNTS_CACHE,
&cache::ROUTING_CACHE,
&cache::CGRAPH_CACHE,
&cache::PM_FILTERS_CGRAPH_CACHE,
&cache::DECISION_MANAGER_CACHE,
&cache::SURCHARGE_CACHE,
];
Expand Down
19 changes: 0 additions & 19 deletions crates/storage_impl/src/redis/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ const SURCHARGE_CACHE_PREFIX: &str = "surcharge";
/// Prefix for cgraph cache key
const CGRAPH_CACHE_PREFIX: &str = "cgraph";

/// Prefix for PM Filter cgraph cache key
const PM_FILTERS_CGRAPH_CACHE_PREFIX: &str = "pm_filters_cgraph";

/// Prefix for all kinds of cache key
const ALL_CACHE_PREFIX: &str = "all_cache_kind";

Expand Down Expand Up @@ -86,16 +83,6 @@ pub static SURCHARGE_CACHE: Lazy<Cache> =
pub static CGRAPH_CACHE: Lazy<Cache> =
Lazy::new(|| Cache::new("CGRAPH_CACHE", CACHE_TTL, CACHE_TTI, Some(MAX_CAPACITY)));

/// PM Filter CGraph Cache
pub static PM_FILTERS_CGRAPH_CACHE: Lazy<Cache> = Lazy::new(|| {
Cache::new(
"PM_FILTERS_CGRAPH_CACHE",
CACHE_TTL,
CACHE_TTI,
Some(MAX_CAPACITY),
)
});

/// Trait which defines the behaviour of types that's gonna be stored in Cache
pub trait Cacheable: Any + Send + Sync + DynClone {
fn as_any(&self) -> &dyn Any;
Expand All @@ -108,7 +95,6 @@ pub enum CacheKind<'a> {
DecisionManager(Cow<'a, str>),
Surcharge(Cow<'a, str>),
CGraph(Cow<'a, str>),
PmFiltersCGraph(Cow<'a, str>),
All(Cow<'a, str>),
}

Expand All @@ -121,7 +107,6 @@ impl<'a> From<CacheKind<'a>> for RedisValue {
CacheKind::DecisionManager(s) => format!("{DECISION_MANAGER_CACHE_PREFIX},{s}"),
CacheKind::Surcharge(s) => format!("{SURCHARGE_CACHE_PREFIX},{s}"),
CacheKind::CGraph(s) => format!("{CGRAPH_CACHE_PREFIX},{s}"),
CacheKind::PmFiltersCGraph(s) => format!("{PM_FILTERS_CGRAPH_CACHE_PREFIX},{s}"),
CacheKind::All(s) => format!("{ALL_CACHE_PREFIX},{s}"),
};
Self::from_string(value)
Expand All @@ -145,10 +130,6 @@ impl<'a> TryFrom<RedisValue> for CacheKind<'a> {
}
SURCHARGE_CACHE_PREFIX => Ok(Self::Surcharge(Cow::Owned(split.1.to_string()))),
CGRAPH_CACHE_PREFIX => Ok(Self::CGraph(Cow::Owned(split.1.to_string()))),
PM_FILTERS_CGRAPH_CACHE_PREFIX => {
Ok(Self::PmFiltersCGraph(Cow::Owned(split.1.to_string())))
}

ALL_CACHE_PREFIX => Ok(Self::All(Cow::Owned(split.1.to_string()))),
_ => Err(validation_err.into()),
}
Expand Down
18 changes: 1 addition & 17 deletions crates/storage_impl/src/redis/pub_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use router_env::{logger, tracing::Instrument};

use crate::redis::cache::{
CacheKey, CacheKind, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE, DECISION_MANAGER_CACHE,
PM_FILTERS_CGRAPH_CACHE, ROUTING_CACHE, SURCHARGE_CACHE,
ROUTING_CACHE, SURCHARGE_CACHE,
};

#[async_trait::async_trait]
Expand Down Expand Up @@ -100,16 +100,6 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
.await;
key
}
CacheKind::PmFiltersCGraph(key) => {
PM_FILTERS_CGRAPH_CACHE
.remove(CacheKey {
key: key.to_string(),
prefix: self.key_prefix.clone(),
})
.await;

key
}
CacheKind::Routing(key) => {
ROUTING_CACHE
.remove(CacheKey {
Expand Down Expand Up @@ -156,12 +146,6 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
prefix: self.key_prefix.clone(),
})
.await;
PM_FILTERS_CGRAPH_CACHE
.remove(CacheKey {
key: key.to_string(),
prefix: self.key_prefix.clone(),
})
.await;
ROUTING_CACHE
.remove(CacheKey {
key: key.to_string(),
Expand Down

0 comments on commit e486641

Please sign in to comment.