feat: add analytics data cache toggle
This commit is contained in:
@@ -9,6 +9,10 @@ import { toUtc } from '../utils/date-uitil';
|
||||
const analysisService = {
|
||||
|
||||
async echarts(c, params) {
|
||||
if (!this.analysisCacheEnabled(c)) {
|
||||
return await this.queryEcharts(c, params);
|
||||
}
|
||||
|
||||
const cacheKey = this.echartsCacheKey(params);
|
||||
const cache = await c.env.kv.get(cacheKey, { type: 'json' });
|
||||
|
||||
@@ -27,6 +31,10 @@ const analysisService = {
|
||||
},
|
||||
|
||||
async refreshEchartsCache(c) {
|
||||
if (!this.analysisCacheEnabled(c)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { keys } = await c.env.kv.list({ prefix: kvConst.ANALYSIS_ECHARTS });
|
||||
|
||||
await Promise.all(keys.map(key => this.refreshEchartsCacheByKey(c, key.name)));
|
||||
@@ -117,6 +125,10 @@ const analysisService = {
|
||||
return {
|
||||
timeZone: decodeURIComponent(cacheKey.replace(kvConst.ANALYSIS_ECHARTS, ''))
|
||||
};
|
||||
},
|
||||
|
||||
analysisCacheEnabled(c) {
|
||||
return c.env.analysis_cache === true || c.env.analysis_cache === 'true';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ domain = "${DOMAIN}" #邮件域名可可配置多个 示例: ["example1.com",
|
||||
admin = "${ADMIN}" #管理员的邮箱 示例: admin@example.com
|
||||
jwt_secret = "${JWT_SECRET}" #jwt令牌的密钥,随便填一串字符串
|
||||
project_link = "${PROJECT_LINK}"
|
||||
analysis_cache = "${ANALYSIS_CACHE}"
|
||||
|
||||
linuxdo_client_id = "${LINUXDO_CLIENT_ID}"
|
||||
linuxdo_client_secret = "${LINUXDO_CLIENT_SECRET}"
|
||||
|
||||
@@ -33,7 +33,8 @@ run_worker_first = true
|
||||
|
||||
|
||||
[vars]
|
||||
ai_model = "@cf/meta/llama-3.1-8b-instruct"
|
||||
ai_model = ""
|
||||
analysis_cache = false
|
||||
orm_log = false
|
||||
domain = ["example.com", "example2.com", "example3.com", "example4.com"]
|
||||
admin = "admin@example.com"
|
||||
|
||||
@@ -34,8 +34,9 @@ crons = ["*/30 * * * *", "0 16 * * *"] #每30分钟刷新分析缓存,每天
|
||||
|
||||
|
||||
[vars]
|
||||
ai_model = ""
|
||||
orm_log = false
|
||||
ai_model = "" #ai模型,不填默认使用@cf/meta/llama-3.1-8b-instruct
|
||||
analysis_cache = false #是否开启分析数据缓存
|
||||
orm_log = false #是否sql日志
|
||||
domain = ["example.com"] #邮件域名可可配置多个 示例: ["example1.com","example2.com"]
|
||||
admin = "admin@example.com" #管理员的邮箱 示例: admin@example.com
|
||||
jwt_secret = "b7f29a1d-18e2-4d3b-941f-f6b2c97c02fd" #jwt令牌的密钥,随便填一串字符串
|
||||
|
||||
@@ -34,6 +34,7 @@ crons = ["*/30 * * * *", "0 16 * * *"] #每30分钟刷新分析缓存,每天
|
||||
|
||||
[vars]
|
||||
ai_model = ""
|
||||
analysis_cache = false
|
||||
#orm_log = false
|
||||
#domain = [] #邮件域名可可配置多个 示例: ["example1.com","example2.com"]
|
||||
#admin = "" #管理员的邮箱 示例: admin@example.com
|
||||
|
||||
Reference in New Issue
Block a user