Browse Source

refactor(cache): 优化微信文章缓存操作并调整定时任务处理逻辑

- 在 AddWechatArticleOpToCache 和 AddWechatArticleLlmOpToCache 函数中添加了对业务模式的检查,只在发布和调试模式下加入缓存
- 注释掉了 task.go 中的 HandleWechatArticleOp 定时任务调用,改为由其他服务处理
Roc 3 weeks ago
parent
commit
fdbceba216
2 changed files with 11 additions and 2 deletions
  1. 9 0
      cache/llm.go
  2. 2 2
      services/task.go

+ 9 - 0
cache/llm.go

@@ -16,6 +16,11 @@ type WechatArticleOp struct {
 // @param source
 // @param source
 // @return bool
 // @return bool
 func AddWechatArticleOpToCache(wechatPlatformId int, source string) bool {
 func AddWechatArticleOpToCache(wechatPlatformId int, source string) bool {
+	// 如果不在发布和调试模式,那么就不加入缓存
+	if !utils.InArrayByStr([]string{utils.BusinessCodeRelease, utils.BusinessCodeDebug}, utils.BusinessCode) {
+		return true
+	}
+
 	record := new(WechatArticleOp)
 	record := new(WechatArticleOp)
 	record.Source = source
 	record.Source = source
 	record.WechatPlatformId = wechatPlatformId
 	record.WechatPlatformId = wechatPlatformId
@@ -37,6 +42,10 @@ func AddWechatArticleOpToCache(wechatPlatformId int, source string) bool {
 // @param source
 // @param source
 // @return bool
 // @return bool
 func AddWechatArticleLlmOpToCache(wechatPlatformId int, source string) bool {
 func AddWechatArticleLlmOpToCache(wechatPlatformId int, source string) bool {
+	// 如果不在发布和调试模式,那么就不加入缓存
+	if !utils.InArrayByStr([]string{utils.BusinessCodeRelease, utils.BusinessCodeDebug}, utils.BusinessCode) {
+		return true
+	}
 	record := new(WechatArticleOp)
 	record := new(WechatArticleOp)
 	record.Source = source
 	record.Source = source
 	record.WechatPlatformId = wechatPlatformId
 	record.WechatPlatformId = wechatPlatformId

+ 2 - 2
services/task.go

@@ -68,8 +68,8 @@ func Task() {
 
 
 	go llm.SaveAllChatRecordsToDB()
 	go llm.SaveAllChatRecordsToDB()
 
 
-	// 定时任务进行微信文章操作
-	go HandleWechatArticleOp()
+	// 定时任务进行微信公众号添加、文章刷新操作(暂不处理了,改成其他服务处理)
+	//go HandleWechatArticleOp()
 
 
 	// 定时任务进行微信文章LLM操作
 	// 定时任务进行微信文章LLM操作
 	go HandleWechatArticleLLmOp()
 	go HandleWechatArticleLLmOp()