refactor(data): 优化数据读取和删除逻辑
This commit is contained in:
@@ -132,7 +132,6 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token不存在" + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
dedupObject, err := db.GetDedupObject(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -145,13 +144,14 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
case "all":
|
||||
keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val()
|
||||
global.RDB.Del(global.RCtx, keys...)
|
||||
global.RDB.Del(global.RCtx, "delete-list:"+input.Token)
|
||||
default:
|
||||
i, err := strconv.Atoi(input.DedupBF)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()})
|
||||
return
|
||||
}
|
||||
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, 1, int64(i)).Val()
|
||||
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, int64(-i), -1).Val()
|
||||
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
|
||||
for _, s := range result {
|
||||
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
|
||||
@@ -162,22 +162,25 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, int64(i), -1)
|
||||
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, 0, int64(-i-1))
|
||||
}
|
||||
|
||||
//删除原始数据
|
||||
switch input.CacheList {
|
||||
case "":
|
||||
case "all":
|
||||
global.RDB.Del(global.RCtx, "list:"+input.Token)
|
||||
global.RDB.Del(global.RCtx, "delete-list:"+input.Token)
|
||||
default:
|
||||
i, err := strconv.Atoi(input.CacheList)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "cache_list设置错误 " + err.Error()})
|
||||
return
|
||||
}
|
||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 1, int64(-i))
|
||||
|
||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 0, int64(-i-1))
|
||||
}
|
||||
//TODO
|
||||
|
||||
//删除去重参考值和原始数据
|
||||
switch input.BothNumber {
|
||||
case "":
|
||||
default:
|
||||
@@ -186,19 +189,20 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "both_number设置错误 " + err.Error()})
|
||||
return
|
||||
}
|
||||
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, 1, int64(i)).Val()
|
||||
|
||||
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, int64(-i), -1).Val()
|
||||
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
|
||||
for _, s := range result {
|
||||
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
|
||||
}
|
||||
pipe.LTrim(global.RCtx, "delete-list:"+input.Token, 0, int64(-i-1))
|
||||
pipe.LTrim(global.RCtx, "list:"+input.Token, 0, int64(-i-1))
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, int64(i), -1)
|
||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, int64(i), -1)
|
||||
}
|
||||
|
||||
//输出信息
|
||||
|
Reference in New Issue
Block a user