Fix previous period data
This commit is contained in:
@@ -131,24 +131,47 @@ export class RedisService {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to generate cache keys
|
||||
_getCacheKey(type, params = {}) {
|
||||
const { timeRange, startDate, endDate, metricId, metric, daily } = params;
|
||||
let key = `klaviyo:${type}`;
|
||||
// Helper to generate cache keys
|
||||
_getCacheKey(type, params = {}) {
|
||||
const {
|
||||
timeRange,
|
||||
startDate,
|
||||
endDate,
|
||||
metricId,
|
||||
metric,
|
||||
daily,
|
||||
cacheKey,
|
||||
isPreviousPeriod
|
||||
} = params;
|
||||
|
||||
if (type === 'stats:details') {
|
||||
key += `:${metric}${daily ? ':daily' : ''}`;
|
||||
}
|
||||
let key = `klaviyo:${type}`;
|
||||
|
||||
if (timeRange) {
|
||||
key += `:${timeRange}${metricId ? `:${metricId}` : ''}`;
|
||||
} else if (startDate && endDate) {
|
||||
key += `:custom:${startDate}:${endDate}${metricId ? `:${metricId}` : ''}`;
|
||||
}
|
||||
|
||||
return key;
|
||||
// Handle "stats:details" for daily or metric-based keys
|
||||
if (type === 'stats:details') {
|
||||
key += `:${metric}${daily ? ':daily' : ''}`;
|
||||
}
|
||||
|
||||
// If a specific cache key is provided, use it (highest priority)
|
||||
if (cacheKey) {
|
||||
key += `:${cacheKey}`;
|
||||
}
|
||||
// Otherwise, build a default cache key
|
||||
else if (timeRange) {
|
||||
key += `:${timeRange}${metricId ? `:${metricId}` : ''}`;
|
||||
if (isPreviousPeriod) {
|
||||
key += ':prev';
|
||||
}
|
||||
} else if (startDate && endDate) {
|
||||
key += `:custom:${startDate}:${endDate}${metricId ? `:${metricId}` : ''}`;
|
||||
if (isPreviousPeriod) {
|
||||
key += ':prev';
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
// Get TTL based on time range
|
||||
_getTTL(timeRange) {
|
||||
const TTL_MAP = {
|
||||
|
||||
Reference in New Issue
Block a user