updateMainCacheWithFinal 更新主缓存系统,支持IsFinal参数
(cacheKey string, results []model.SearchResult, isFinal bool)
| 1079 | |
| 1080 | // updateMainCacheWithFinal 更新主缓存系统,支持IsFinal参数 |
| 1081 | func (p *BaseAsyncPlugin) updateMainCacheWithFinal(cacheKey string, results []model.SearchResult, isFinal bool) { |
| 1082 | // 如果主缓存更新函数为空或缓存键为空,直接返回 |
| 1083 | if p.mainCacheUpdater == nil || cacheKey == "" { |
| 1084 | return |
| 1085 | } |
| 1086 | |
| 1087 | // 🚀 优化:如果新结果为空,跳过缓存更新(避免无效操作) |
| 1088 | if len(results) == 0 { |
| 1089 | return |
| 1090 | } |
| 1091 | |
| 1092 | // 🔥 增强防重复更新机制 - 使用数据哈希确保真正的去重 |
| 1093 | // 生成结果数据的简单哈希标识 |
| 1094 | dataHash := fmt.Sprintf("%d_%d", len(results), results[0].UniqueID) |
| 1095 | if len(results) > 1 { |
| 1096 | dataHash += fmt.Sprintf("_%d", results[len(results)-1].UniqueID) |
| 1097 | } |
| 1098 | updateKey := fmt.Sprintf("final_%s_%s_%s_%t", p.name, cacheKey, dataHash, isFinal) |
| 1099 | |
| 1100 | // 检查是否已经处理过相同的数据 |
| 1101 | if p.hasUpdatedFinalCache(updateKey) { |
| 1102 | return |
| 1103 | } |
| 1104 | |
| 1105 | // 标记已更新 |
| 1106 | p.markFinalCacheUpdated(updateKey) |
| 1107 | |
| 1108 | // 🔧 恢复异步插件缓存更新,使用修复后的统一序列化 |
| 1109 | // 传递原始数据,由主程序负责GOB序列化 |
| 1110 | if p.mainCacheUpdater != nil { |
| 1111 | err := p.mainCacheUpdater(cacheKey, results, p.cacheTTL, isFinal, p.currentKeyword) |
| 1112 | if err != nil { |
| 1113 | fmt.Printf("❌ [%s] 主缓存更新失败: %s | 错误: %v\n", p.name, cacheKey, err) |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | // hasUpdatedFinalCache 检查是否已经更新过指定的最终结果缓存 |
| 1119 | func (p *BaseAsyncPlugin) hasUpdatedFinalCache(updateKey string) bool { |
no test coverage detected