File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -337,8 +337,10 @@ func (b *BadgerDB) FindAll(prefix string, result interface{}) error {
337337 // 针对不同的数据类型进行特殊处理
338338 switch prefix {
339339 case "server" :
340- // 服务器记录可能需要特殊处理
340+ // 服务器记录可能需要特殊处理,并且需要去重
341341 var servers []* map [string ]interface {}
342+ seenIDs := make (map [uint64 ]bool ) // 用于去重
343+
342344 for _ , item := range items {
343345 var data map [string ]interface {}
344346 if err := json .Unmarshal (item , & data ); err != nil {
@@ -347,9 +349,23 @@ func (b *BadgerDB) FindAll(prefix string, result interface{}) error {
347349
348350 // 转换字段类型,确保 JSON 字段正确
349351 convertDbFieldTypes (& data )
352+
353+ // 检查是否重复ID
354+ if idVal , exists := data ["ID" ]; exists {
355+ if id , ok := idVal .(uint64 ); ok {
356+ if seenIDs [id ] {
357+ log .Printf ("FindAll: 跳过重复的服务器ID %d" , id )
358+ continue // 跳过重复的ID
359+ }
360+ seenIDs [id ] = true
361+ }
362+ }
363+
350364 servers = append (servers , & data )
351365 }
352366
367+ log .Printf ("FindAll: 去重后保留 %d 个服务器记录" , len (servers ))
368+
353369 // 重新序列化为 JSON
354370 serversJSON , err := json .Marshal (servers )
355371 if err != nil {
You can’t perform that action at this time.
0 commit comments