fix(backend): don't use redis GETDEL
This commit is contained in:
parent
661f0254fd
commit
86a1841f4f
|
@ -137,30 +137,6 @@ func (db *DB) GetJSON(ctx context.Context, key string, v any) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDelJSON gets the given key as a JSON object and deletes it.
|
|
||||||
func (db *DB) GetDelJSON(ctx context.Context, key string, v any) error {
|
|
||||||
var b []byte
|
|
||||||
|
|
||||||
err := db.Redis.Do(ctx, radix.Cmd(&b, "GETDEL", key))
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "reading from Redis")
|
|
||||||
}
|
|
||||||
|
|
||||||
if b == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if v == nil {
|
|
||||||
return fmt.Errorf("nil pointer passed into GetDelJSON")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(b, v)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "unmarshaling json")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotNull is a little helper that returns an *empty slice* when the slice's length is 0.
|
// NotNull is a little helper that returns an *empty slice* when the slice's length is 0.
|
||||||
// This is to prevent nil slices from being marshaled as JSON null
|
// This is to prevent nil slices from being marshaled as JSON null
|
||||||
func NotNull[T any](slice []T) []T {
|
func NotNull[T any](slice []T) []T {
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (s *Server) saveUndeleteToken(ctx context.Context, userID xid.ID, token str
|
||||||
|
|
||||||
func (s *Server) getUndeleteToken(ctx context.Context, token string) (userID xid.ID, err error) {
|
func (s *Server) getUndeleteToken(ctx context.Context, token string) (userID xid.ID, err error) {
|
||||||
var idString string
|
var idString string
|
||||||
err = s.DB.Redis.Do(ctx, radix.Cmd(&idString, "GETDEL", "undelete:"+token))
|
err = s.DB.Redis.Do(ctx, radix.Cmd(&idString, "GET", "undelete:"+token))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userID, errors.Wrap(err, "getting undelete key")
|
return userID, errors.Wrap(err, "getting undelete key")
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,11 @@ func (s *Server) getUndeleteToken(ctx context.Context, token string) (userID xid
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userID, errors.Wrap(err, "parsing ID")
|
return userID, errors.Wrap(err, "parsing ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = s.DB.Redis.Do(ctx, radix.Cmd(nil, "DEL", "undelete:"+token))
|
||||||
|
if err != nil {
|
||||||
|
return userID, errors.Wrap(err, "deleting undelete key")
|
||||||
|
}
|
||||||
return userID, nil
|
return userID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue