From 9fa8f9fa6247ceded90fcaf89f55b5703cec7971 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 24 May 2026 17:21:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(llmage):=20=E6=97=A5=E6=9C=9F=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E8=A7=A6=E5=8F=91=E5=A4=87=E4=BB=BD(use=5Fdate= 30: - backup_counter = 0 + # Check if date changed, trigger backup once per day + today = datetime.now().strftime('%Y-%m-%d') + if today != last_backup_date: + yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d') + last_backup_date = today try: - await backup_accounted_llmusage() + debug(f'date changed to {today}, triggering backup for use_date < {yesterday}') + await backup_accounted_llmusage(yesterday) except Exception as e: exception(f'backup_accounted_llmusage failed: {e}') diff --git a/models/llmusage.json b/models/llmusage.json index 7d0f6ca..3371734 100644 --- a/models/llmusage.json +++ b/models/llmusage.json @@ -123,6 +123,14 @@ "idxfields": [ "userid" ] + }, + { + "name": "idx_llmusage_accounting", + "idxtype": "index", + "idxfields": [ + "accounting_status", + "use_date" + ] } ] } \ No newline at end of file diff --git a/scripts/migrate_llmusage_history.sql b/scripts/migrate_llmusage_history.sql index 5c30e0c..9bebf84 100644 --- a/scripts/migrate_llmusage_history.sql +++ b/scripts/migrate_llmusage_history.sql @@ -69,6 +69,9 @@ CREATE INDEX idx_laf_llmid ON llmusage_accounting_failed(llmid); CREATE INDEX idx_laf_handled ON llmusage_accounting_failed(handled); CREATE INDEX idx_laf_failed_time ON llmusage_accounting_failed(failed_time); +-- 3. 为 llmusage 表添加组合索引(优化备份查询: accounting_status + use_date) +CREATE INDEX idx_llmusage_accounting ON llmusage(accounting_status, use_date); + -- ============================================================ -- 验证步骤(执行后运行): -- 1. 确认表创建成功: