|
|
@@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
public class KuaishouHotStore {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(KuaishouHotStore.class);
|
|
|
+ private static final Duration IMPRESSION_BID_TTL = Duration.ofHours(3);
|
|
|
private static final Duration DEFAULT_CONVERSION_SEEN_TTL = Duration.ofDays(7);
|
|
|
private static final Duration DEFAULT_DEDUCTION_COUNTER_TTL = Duration.ofDays(7);
|
|
|
|
|
|
@@ -69,7 +70,7 @@ public class KuaishouHotStore {
|
|
|
redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
|
|
|
trimStreamIfNeeded(conn);
|
|
|
byte[] hotBytes = hotPayload.getBytes(StandardCharsets.UTF_8);
|
|
|
- long ttlMillis = bidTtl.toMillis();
|
|
|
+ long ttlMillis = bidTtlFor(record.getEventType()).toMillis();
|
|
|
if (record.getQk() != null && !record.getQk().isBlank()) {
|
|
|
conn.stringCommands().set(
|
|
|
bidKey(record.getQk()).getBytes(StandardCharsets.UTF_8),
|
|
|
@@ -112,9 +113,7 @@ public class KuaishouHotStore {
|
|
|
try {
|
|
|
String slimPayload = objectMapper.writeValueAsString(record.toPostClickRecord());
|
|
|
byte[] slimBytes = slimPayload.getBytes(StandardCharsets.UTF_8);
|
|
|
- Long remainingTtl = redis.getExpire(bidKey(record.getQk()), java.util.concurrent.TimeUnit.MILLISECONDS);
|
|
|
- if (remainingTtl == null || remainingTtl <= 0) remainingTtl = bidTtl.toMillis();
|
|
|
- long ttlMs = remainingTtl;
|
|
|
+ long ttlMs = resolvedBidTtl().toMillis();
|
|
|
redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
|
|
|
if (record.getQk() != null && !record.getQk().isBlank()) {
|
|
|
conn.stringCommands().set(
|
|
|
@@ -145,6 +144,14 @@ public class KuaishouHotStore {
|
|
|
return parseBidRecord(payload);
|
|
|
}
|
|
|
|
|
|
+ private Duration bidTtlFor(String eventType) {
|
|
|
+ return "impression".equalsIgnoreCase(eventType) ? IMPRESSION_BID_TTL : resolvedBidTtl();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Duration resolvedBidTtl() {
|
|
|
+ return (bidTtl == null || bidTtl.isZero()) ? Duration.ofHours(36) : bidTtl;
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, KuaishouBidRecord> findBidsByQks(List<String> qks) {
|
|
|
if (qks == null || qks.isEmpty()) return Collections.emptyMap();
|
|
|
Map<String, KuaishouBidRecord> result = new HashMap<>();
|