From 44bbf9c3dadb177e7b8d37864c827b09b1638e6b Mon Sep 17 00:00:00 2001 From: eoao Date: Sun, 10 May 2026 13:12:22 +0800 Subject: [PATCH] feat: add analytics data cache toggle --- mail-worker/src/service/analysis-service.js | 12 ++++++++++++ mail-worker/wrangler-action.toml | 1 + mail-worker/wrangler-dev.toml | 3 ++- mail-worker/wrangler-test.toml | 5 +++-- mail-worker/wrangler.toml | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mail-worker/src/service/analysis-service.js b/mail-worker/src/service/analysis-service.js index d46b40d..02ca2fe 100644 --- a/mail-worker/src/service/analysis-service.js +++ b/mail-worker/src/service/analysis-service.js @@ -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'; } } diff --git a/mail-worker/wrangler-action.toml b/mail-worker/wrangler-action.toml index 2c6b4da..d621303 100644 --- a/mail-worker/wrangler-action.toml +++ b/mail-worker/wrangler-action.toml @@ -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}" diff --git a/mail-worker/wrangler-dev.toml b/mail-worker/wrangler-dev.toml index 28c0fb8..7b88089 100644 --- a/mail-worker/wrangler-dev.toml +++ b/mail-worker/wrangler-dev.toml @@ -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" diff --git a/mail-worker/wrangler-test.toml b/mail-worker/wrangler-test.toml index 9d3cc73..79c0a82 100644 --- a/mail-worker/wrangler-test.toml +++ b/mail-worker/wrangler-test.toml @@ -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令牌的密钥,随便填一串字符串 diff --git a/mail-worker/wrangler.toml b/mail-worker/wrangler.toml index 2410453..f44d028 100644 --- a/mail-worker/wrangler.toml +++ b/mail-worker/wrangler.toml @@ -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