|
|
@@ -205,9 +205,25 @@ export class MessageRecordService {
|
|
|
page: number = MessageRecordService.DEFAULT_STATS_PAGE,
|
|
|
limit: number = MessageRecordService.DEFAULT_STATS_LIMIT
|
|
|
) {
|
|
|
+ const cacheKey = this.buildStatsCacheKey("by-template", {
|
|
|
+ startDate: startDate?.toISOString(),
|
|
|
+ endDate: endDate?.toISOString(),
|
|
|
+ strategyName: strategyName || null,
|
|
|
+ page,
|
|
|
+ limit,
|
|
|
+ });
|
|
|
+ const cached = await this.getCache(cacheKey);
|
|
|
+ if (cached) {
|
|
|
+ console.log(`[MessageStatsCache] hit key=${cacheKey}`);
|
|
|
+ return cached;
|
|
|
+ }
|
|
|
const matchConditions = this.buildMatchConditions(startDate, endDate, strategyName);
|
|
|
- const groupFields = ["templateId", "templateName"];
|
|
|
- return this.getStatisticsByGroup(matchConditions, groupFields, { clickThroughRate: -1 }, page, limit);
|
|
|
+ // templateId 是 ObjectId,分组时增加基数但对展示无意义,移除后减少第一阶段 group key 大小
|
|
|
+ const groupFields = ["templateName"];
|
|
|
+ const result = await this.getStatisticsByGroup(matchConditions, groupFields, { clickThroughRate: -1 }, page, limit);
|
|
|
+ await this.setCache(cacheKey, result);
|
|
|
+ console.log(`[MessageStatsCache] miss key=${cacheKey}`);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -220,9 +236,23 @@ export class MessageRecordService {
|
|
|
page: number = MessageRecordService.DEFAULT_STATS_PAGE,
|
|
|
limit: number = MessageRecordService.DEFAULT_STATS_LIMIT
|
|
|
) {
|
|
|
+ const cacheKey = this.buildStatsCacheKey("by-cc", {
|
|
|
+ startDate: startDate?.toISOString(),
|
|
|
+ endDate: endDate?.toISOString(),
|
|
|
+ strategyName: strategyName || null,
|
|
|
+ page,
|
|
|
+ limit,
|
|
|
+ });
|
|
|
+ const cached = await this.getCache(cacheKey);
|
|
|
+ if (cached) {
|
|
|
+ console.log(`[MessageStatsCache] hit key=${cacheKey}`);
|
|
|
+ return cached;
|
|
|
+ }
|
|
|
const matchConditions = this.buildMatchConditions(startDate, endDate, strategyName);
|
|
|
- const groupFields = ["cc"];
|
|
|
- return this.getStatisticsByGroup(matchConditions, groupFields, { totalRecords: -1 }, page, limit);
|
|
|
+ const result = await this.getStatisticsByGroup(matchConditions, ["cc"], { totalRecords: -1 }, page, limit);
|
|
|
+ await this.setCache(cacheKey, result);
|
|
|
+ console.log(`[MessageStatsCache] miss key=${cacheKey}`);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -235,9 +265,23 @@ export class MessageRecordService {
|
|
|
page: number = MessageRecordService.DEFAULT_STATS_PAGE,
|
|
|
limit: number = MessageRecordService.DEFAULT_STATS_LIMIT
|
|
|
) {
|
|
|
+ const cacheKey = this.buildStatsCacheKey("by-image", {
|
|
|
+ startDate: startDate?.toISOString(),
|
|
|
+ endDate: endDate?.toISOString(),
|
|
|
+ strategyName: strategyName || null,
|
|
|
+ page,
|
|
|
+ limit,
|
|
|
+ });
|
|
|
+ const cached = await this.getCache(cacheKey);
|
|
|
+ if (cached) {
|
|
|
+ console.log(`[MessageStatsCache] hit key=${cacheKey}`);
|
|
|
+ return cached;
|
|
|
+ }
|
|
|
const matchConditions = this.buildMatchConditions(startDate, endDate, strategyName);
|
|
|
- const groupFields = ["image"];
|
|
|
- return this.getStatisticsByGroup(matchConditions, groupFields, { clickThroughRate: -1 }, page, limit);
|
|
|
+ const result = await this.getStatisticsByGroup(matchConditions, ["image"], { clickThroughRate: -1 }, page, limit);
|
|
|
+ await this.setCache(cacheKey, result);
|
|
|
+ console.log(`[MessageStatsCache] miss key=${cacheKey}`);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|