Skip to content

Commit 1604e92

Browse files
committed
invalidate the cache for decision manager as well as surcharge
1 parent 0a5c04a commit 1604e92

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

crates/router/src/core/conditional_config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub async fn upsert_conditional_config(
9999
.change_context(errors::ApiErrorResponse::InternalServerError)
100100
.attach_printable("Error serializing the config")?;
101101

102-
algo_id.update_conditional_config_id(key);
103-
update_merchant_active_algorithm_ref(db, &key_store, algo_id)
102+
algo_id.update_conditional_config_id(key.clone());
103+
update_merchant_active_algorithm_ref(db, &key_store, &key, algo_id)
104104
.await
105105
.change_context(errors::ApiErrorResponse::InternalServerError)
106106
.attach_printable("Failed to update routing algorithm ref")?;
@@ -134,8 +134,8 @@ pub async fn upsert_conditional_config(
134134
.change_context(errors::ApiErrorResponse::InternalServerError)
135135
.attach_printable("Error fetching the config")?;
136136

137-
algo_id.update_conditional_config_id(key);
138-
update_merchant_active_algorithm_ref(db, &key_store, algo_id)
137+
algo_id.update_conditional_config_id(key.clone());
138+
update_merchant_active_algorithm_ref(db, &key_store, &key, algo_id)
139139
.await
140140
.change_context(errors::ApiErrorResponse::InternalServerError)
141141
.attach_printable("Failed to update routing algorithm ref")?;
@@ -164,7 +164,7 @@ pub async fn delete_conditional_config(
164164
.attach_printable("Could not decode the conditional_config algorithm")?
165165
.unwrap_or_default();
166166
algo_id.config_algo_id = None;
167-
update_merchant_active_algorithm_ref(db, &key_store, algo_id)
167+
update_merchant_active_algorithm_ref(db, &key_store, &key, algo_id)
168168
.await
169169
.change_context(errors::ApiErrorResponse::InternalServerError)
170170
.attach_printable("Failed to update deleted algorithm ref")?;

crates/router/src/core/routing.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ pub async fn create_routing_config(
232232
if records_are_empty {
233233
merchant_dictionary.active_id = Some(algorithm_id.clone());
234234
algorithm_ref.update_algorithm_id(algorithm_id);
235-
helpers::update_merchant_active_algorithm_ref(db, &key_store, algorithm_ref).await?;
235+
let key = format!("dsl_{merchant_id}");
236+
helpers::update_merchant_active_algorithm_ref(db, &key_store, &key, algorithm_ref)
237+
.await?;
236238
}
237239

238240
helpers::update_merchant_routing_dictionary(
@@ -363,7 +365,8 @@ pub async fn link_routing_config(
363365
merchant_dictionary,
364366
)
365367
.await?;
366-
helpers::update_merchant_active_algorithm_ref(db, &key_store, routing_ref).await?;
368+
let key = format!("dsl_{merchant_id}");
369+
helpers::update_merchant_active_algorithm_ref(db, &key_store, &key, routing_ref).await?;
367370

368371
metrics::ROUTING_LINK_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
369372
Ok(service_api::ApplicationResponse::Json(response))

crates/router/src/core/routing/helpers.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ pub async fn update_routing_algorithm(
188188
pub async fn update_merchant_active_algorithm_ref(
189189
db: &dyn StorageInterface,
190190
key_store: &domain::MerchantKeyStore,
191+
key: &str,
191192
algorithm_id: routing_types::RoutingAlgorithmRef,
192193
) -> RouterResult<()> {
193194
let ref_value = algorithm_id
@@ -216,7 +217,7 @@ pub async fn update_merchant_active_algorithm_ref(
216217
default_profile: None,
217218
payment_link_config: None,
218219
};
219-
220+
let config_key = cache::CacheKind::Config(key.into());
220221
db.update_specific_fields_in_merchant(
221222
&key_store.merchant_id,
222223
merchant_account_update,
@@ -226,6 +227,11 @@ pub async fn update_merchant_active_algorithm_ref(
226227
.change_context(errors::ApiErrorResponse::InternalServerError)
227228
.attach_printable("Failed to update routing algorithm ref in merchant account")?;
228229

230+
cache::publish_into_redact_channel(db.get_cache_store().as_ref(), [config_key])
231+
.await
232+
.change_context(errors::ApiErrorResponse::InternalServerError)
233+
.attach_printable("Failed to invalidate the config cache")?;
234+
229235
Ok(())
230236
}
231237

crates/router/src/core/surcharge_decision_config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ pub async fn upsert_surcharge_decision_config(
8888
.change_context(errors::ApiErrorResponse::InternalServerError)
8989
.attach_printable("Error serializing the config")?;
9090

91-
algo_id.update_surcharge_config_id(key);
92-
update_merchant_active_algorithm_ref(db, &key_store, algo_id)
91+
algo_id.update_surcharge_config_id(key.clone());
92+
update_merchant_active_algorithm_ref(db, &key_store, &key, algo_id)
9393
.await
9494
.change_context(errors::ApiErrorResponse::InternalServerError)
9595
.attach_printable("Failed to update routing algorithm ref")?;
@@ -124,8 +124,8 @@ pub async fn upsert_surcharge_decision_config(
124124
.change_context(errors::ApiErrorResponse::InternalServerError)
125125
.attach_printable("Error fetching the config")?;
126126

127-
algo_id.update_surcharge_config_id(key);
128-
update_merchant_active_algorithm_ref(db, &key_store, algo_id)
127+
algo_id.update_surcharge_config_id(key.clone());
128+
update_merchant_active_algorithm_ref(db, &key_store, &key, algo_id)
129129
.await
130130
.change_context(errors::ApiErrorResponse::InternalServerError)
131131
.attach_printable("Failed to update routing algorithm ref")?;
@@ -154,7 +154,7 @@ pub async fn delete_surcharge_decision_config(
154154
.attach_printable("Could not decode the surcharge conditional_config algorithm")?
155155
.unwrap_or_default();
156156
algo_id.surcharge_config_algo_id = None;
157-
update_merchant_active_algorithm_ref(db, &key_store, algo_id)
157+
update_merchant_active_algorithm_ref(db, &key_store, &key, algo_id)
158158
.await
159159
.change_context(errors::ApiErrorResponse::InternalServerError)
160160
.attach_printable("Failed to update deleted algorithm ref")?;

0 commit comments

Comments
 (0)