feat: 全面优化系统 - 修复task1语法错误 + Bot超时保护 + 熔断重试 + Redis缓存 + SEO + 日志清理 + 内容质量评估

This commit is contained in:
ZhuiGuangAI Dev
2026-06-13 15:26:39 +08:00
parent a0a60ee9dc
commit b44601bb66
12 changed files with 399 additions and 12 deletions
+15
View File
@@ -3,6 +3,7 @@ import { PrismaMariaDb } from "@prisma/adapter-mariadb";
import OpenAI from "openai";
import "dotenv/config";
import { withRetry } from "./lib/retry.mjs";
import { cacheGet, cacheSet, disconnectRedis } from "./lib/redis-cache.mjs";
const rawUrl = process.env.DATABASE_URL;
if (!rawUrl) { console.error("DATABASE_URL not set"); process.exit(1); }
@@ -20,6 +21,14 @@ const openai = new OpenAI({
});
async function fetchRSS(rssUrl, source) {
// 缓存 RSS 结果 30 分钟,避免重复请求
const cacheKey = `rss:${source}:${rssUrl}`;
const cached = await cacheGet(cacheKey);
if (cached) {
console.log(` 📦 ${source} RSS 命中缓存 (${cached.length} 条)`);
return cached;
}
try {
const response = await fetch(rssUrl, {
headers: { "User-Agent": "Mozilla/5.0 (compatible; NewsBot/1.0)" },
@@ -46,6 +55,11 @@ async function fetchRSS(rssUrl, source) {
});
}
}
// 缓存 30 分钟
if (items.length > 0) {
await cacheSet(cacheKey, items, 1800);
}
return items;
} catch (e) {
console.error(` ⚠️ ${source} RSS获取失败: ${e.message}`);
@@ -391,6 +405,7 @@ async function main() {
process.exit(1);
} finally {
await prisma.$disconnect();
await disconnectRedis();
}
}