Commit d77d0544 authored by yangjianbo's avatar yangjianbo
Browse files

fix(仓储): 修复并发缓存前缀与软删除更新

补齐 Redis ZSET 前缀处理,确保并发释放计数正确

删除时改用 Client().Mutate 走更新逻辑,保留软删除记录

测试: make test-integration
parent 682f546c
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin" "entgo.io/ent/schema/mixin"
dbent "github.com/Wei-Shaw/sub2api/ent"
"github.com/Wei-Shaw/sub2api/ent/intercept" "github.com/Wei-Shaw/sub2api/ent/intercept"
) )
...@@ -112,6 +113,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook { ...@@ -112,6 +113,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
SetOp(ent.Op) SetOp(ent.Op)
SetDeletedAt(time.Time) SetDeletedAt(time.Time)
WhereP(...func(*sql.Selector)) WhereP(...func(*sql.Selector))
Client() *dbent.Client
}) })
if !ok { if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m) return nil, fmt.Errorf("unexpected mutation type %T", m)
...@@ -122,7 +124,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook { ...@@ -122,7 +124,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
mx.SetOp(ent.OpUpdate) mx.SetOp(ent.OpUpdate)
// 设置删除时间为当前时间 // 设置删除时间为当前时间
mx.SetDeletedAt(time.Now()) mx.SetDeletedAt(time.Now())
return next.Mutate(ctx, m) return mx.Client().Mutate(ctx, m)
}) })
}, },
} }
......
...@@ -330,7 +330,8 @@ func (h prefixHook) prefixCmd(cmd redisclient.Cmder) { ...@@ -330,7 +330,8 @@ func (h prefixHook) prefixCmd(cmd redisclient.Cmder) {
switch strings.ToLower(cmd.Name()) { switch strings.ToLower(cmd.Name()) {
case "get", "set", "setnx", "setex", "psetex", "incr", "decr", "incrby", "expire", "pexpire", "ttl", "pttl", case "get", "set", "setnx", "setex", "psetex", "incr", "decr", "incrby", "expire", "pexpire", "ttl", "pttl",
"hgetall", "hget", "hset", "hdel", "hincrbyfloat", "exists": "hgetall", "hget", "hset", "hdel", "hincrbyfloat", "exists",
"zadd", "zcard", "zrange", "zrangebyscore", "zrem", "zremrangebyscore", "zrevrange", "zrevrangebyscore", "zscore":
prefixOne(1) prefixOne(1)
case "del", "unlink": case "del", "unlink":
for i := 1; i < len(args); i++ { for i := 1; i < len(args); i++ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment