From 74c9a700647b588032f13acfd21762bc60360942 Mon Sep 17 00:00:00 2001 From: Serhii Kolomiiets Date: Wed, 28 Feb 2024 15:34:01 +0200 Subject: [PATCH] Post-review fixes --- .../USCustomLogicModuleCreator.java | 10 ++-------- .../ActivityInfrastructureConfiguration.java | 20 +++++++++++++++---- .../USCustomLogicModuleCreatorTest.java | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreator.java b/src/main/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreator.java index baf29d12151..f7266fc311b 100644 --- a/src/main/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreator.java +++ b/src/main/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreator.java @@ -19,7 +19,6 @@ import org.prebid.server.json.JsonLogic; import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; -import org.prebid.server.settings.SettingsCache; import org.prebid.server.settings.model.activity.privacy.AccountUSCustomLogicModuleConfig; import java.util.Collection; @@ -46,18 +45,13 @@ public class USCustomLogicModuleCreator implements PrivacyModuleCreator { public USCustomLogicModuleCreator(USCustomLogicGppReaderFactory gppReaderFactory, JsonLogic jsonLogic, - Integer cacheTtl, - Integer cacheSize, - int jitter, + Map jsonLogicNodesCache, Metrics metrics) { this.gppReaderFactory = Objects.requireNonNull(gppReaderFactory); this.jsonLogic = Objects.requireNonNull(jsonLogic); this.metrics = Objects.requireNonNull(metrics); - - jsonLogicNodesCache = cacheTtl != null && cacheSize != null - ? SettingsCache.createCache(cacheTtl, cacheSize, jitter) - : null; + this.jsonLogicNodesCache = jsonLogicNodesCache; } @Override diff --git a/src/main/java/org/prebid/server/spring/config/ActivityInfrastructureConfiguration.java b/src/main/java/org/prebid/server/spring/config/ActivityInfrastructureConfiguration.java index 9bd2cd2d4a3..8559c4abd76 100644 --- a/src/main/java/org/prebid/server/spring/config/ActivityInfrastructureConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ActivityInfrastructureConfiguration.java @@ -1,5 +1,6 @@ package org.prebid.server.spring.config; +import io.github.jamsesso.jsonlogic.ast.JsonLogicNode; import org.prebid.server.activity.infrastructure.creator.ActivityInfrastructureCreator; import org.prebid.server.activity.infrastructure.creator.ActivityRuleFactory; import org.prebid.server.activity.infrastructure.creator.privacy.PrivacyModuleCreator; @@ -13,11 +14,13 @@ import org.prebid.server.activity.infrastructure.creator.rule.RuleCreator; import org.prebid.server.json.JsonLogic; import org.prebid.server.metric.Metrics; +import org.prebid.server.settings.SettingsCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.List; +import java.util.Map; @Configuration public class ActivityInfrastructureConfiguration { @@ -47,17 +50,26 @@ USCustomLogicGppReaderFactory usCustomLogicGppReaderFactory() { return new USCustomLogicGppReaderFactory(); } + @Bean + Map jsonLogicNodesCache( + @Value("${settings.in-memory-cache.ttl-seconds:#{null}}") Integer ttlSeconds, + @Value("${settings.in-memory-cache.cache-size:#{null}}") Integer cacheSize, + @Value("${settings.in-memory-cache.cache-size:0}") int jitter) { + + return ttlSeconds != null && cacheSize != null + ? SettingsCache.createCache(ttlSeconds, cacheSize, jitter) + : null; + } + @Bean USCustomLogicModuleCreator usCustomLogicModuleCreator( USCustomLogicGppReaderFactory gppReaderFactory, JsonLogic jsonLogic, - @Value("${settings.in-memory-cache.ttl-seconds:#{null}}") Integer ttlSeconds, - @Value("${settings.in-memory-cache.cache-size:#{null}}") Integer cacheSize, - @Value("${settings.in-memory-cache.cache-size:0}") int jitter, + Map jsonLogicNodesCache, Metrics metrics) { return new USCustomLogicModuleCreator( - gppReaderFactory, jsonLogic, ttlSeconds, cacheSize, jitter, metrics); + gppReaderFactory, jsonLogic, jsonLogicNodesCache, metrics); } } } diff --git a/src/test/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreatorTest.java b/src/test/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreatorTest.java index 6eda2101332..8c3091e952d 100644 --- a/src/test/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreatorTest.java +++ b/src/test/java/org/prebid/server/activity/infrastructure/creator/privacy/uscustomlogic/USCustomLogicModuleCreatorTest.java @@ -64,7 +64,7 @@ public void setUp() { .willReturn(new USNationalGppReader(null)); given(jsonLogic.parse(any())).willReturn(JsonLogicBoolean.TRUE); - target = new USCustomLogicModuleCreator(gppReaderFactory, jsonLogic, null, null, 0, metrics); + target = new USCustomLogicModuleCreator(gppReaderFactory, jsonLogic, null, metrics); } @Test