diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 2cddfa257..28f836ea4 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -620,6 +620,18 @@ func (rs *RedisStorage) GetAccount(key string) (ub *Account, err error) { } func (rs *RedisStorage) SetAccount(ub *Account) (err error) { + // never override existing account with an empty one + // UPDATE: if all balances expired and were cleaned it makes + // sense to write empty balance map + if len(ub.BalanceMap) == 0 { + if ac, err := rs.GetAccount(ub.Id); err == nil && !ac.allBalancesExpired() { + ac.ActionTriggers = ub.ActionTriggers + ac.UnitCounters = ub.UnitCounters + ac.AllowNegative = ub.AllowNegative + ac.Disabled = ub.Disabled + ub = ac + } + } result, err := rs.ms.Marshal(ub) err = rs.db.Cmd("SET", utils.ACCOUNT_PREFIX+ub.Id, result).Err return