|
@@ -90,7 +90,6 @@ func GetChatRecordsFromRedis(chatId int) (redisList []*llm.UserChatRecordRedis,
|
|
|
func flushRecordsToRedis(chatId int) (err error) {
|
|
|
key := fmt.Sprintf("%s%d", redisChatPrefix, chatId)
|
|
|
zSet, _ := utils.Rc.ZRangeWithScores(key)
|
|
|
- var redisList []*llm.UserChatRecordRedis
|
|
|
if len(zSet) == 0 {
|
|
|
// 缓存不存在,从数据库拉取数据
|
|
|
records, dbErr := GetChatRecordsFromDB(chatId)
|
|
@@ -108,7 +107,7 @@ func flushRecordsToRedis(chatId int) (err error) {
|
|
|
Content: record.Content,
|
|
|
SendTime: record.SendTime.Format(utils.FormatDateTime),
|
|
|
}
|
|
|
- data, parseErr := json.Marshal(&record)
|
|
|
+ data, parseErr := json.Marshal(&redisRecord)
|
|
|
if parseErr != nil {
|
|
|
utils.FileLog.Error("解析聊天记录失败: %w", err)
|
|
|
}
|
|
@@ -116,8 +115,8 @@ func flushRecordsToRedis(chatId int) (err error) {
|
|
|
Member: data,
|
|
|
Score: float64(record.SendTime.Unix()),
|
|
|
})
|
|
|
- redisList = append(redisList, redisRecord)
|
|
|
}
|
|
|
+ _ = utils.Rc.ZAdd(key, zet...)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -194,7 +193,7 @@ func SaveAllChatRecordsToDB() {
|
|
|
}
|
|
|
wg.Wait()
|
|
|
fmt.Printf("计划任务完成")
|
|
|
- time.Sleep(60 * time.Second)
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
}
|
|
|
}
|
|
|
|