mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
various cache fixes
This commit is contained in:
@@ -330,27 +330,27 @@ func (at *ActionPlan) String_DISABLED() string {
|
||||
}
|
||||
|
||||
// Helper to remove ActionPlan members based on specific filters, empty data means no always match
|
||||
func RemActionPlan(ats ActionPlans, actionTimingId, balanceId string) ActionPlans {
|
||||
func RemActionPlan(ats ActionPlans, actionTimingId, accountId string) ActionPlans {
|
||||
for idx, at := range ats {
|
||||
if len(actionTimingId) != 0 && at.Uuid != actionTimingId { // No Match for ActionPlanId, no need to move further
|
||||
continue
|
||||
}
|
||||
if len(balanceId) == 0 { // No account defined, considered match for complete removal
|
||||
if len(accountId) == 0 { // No account defined, considered match for complete removal
|
||||
if len(ats) == 1 { // Removing last item, by init empty
|
||||
return make([]*ActionPlan, 0)
|
||||
}
|
||||
ats[idx], ats = ats[len(ats)-1], ats[:len(ats)-1]
|
||||
continue
|
||||
}
|
||||
for iBlnc, blncId := range at.AccountIds {
|
||||
if blncId == balanceId {
|
||||
for iAcc, accId := range at.AccountIds {
|
||||
if accId == accountId {
|
||||
if len(at.AccountIds) == 1 { // Only one balance, remove complete at
|
||||
if len(ats) == 1 { // Removing last item, by init empty
|
||||
return make([]*ActionPlan, 0)
|
||||
}
|
||||
ats[idx], ats = ats[len(ats)-1], ats[:len(ats)-1]
|
||||
} else {
|
||||
at.AccountIds[iBlnc], at.AccountIds = at.AccountIds[len(at.AccountIds)-1], at.AccountIds[:len(at.AccountIds)-1]
|
||||
at.AccountIds[iAcc], at.AccountIds = at.AccountIds[len(at.AccountIds)-1], at.AccountIds[:len(at.AccountIds)-1]
|
||||
}
|
||||
// only remove the first one matching
|
||||
break
|
||||
|
||||
@@ -699,6 +699,7 @@ func (ms *MapStorage) SetActionPlans(key string, ats ActionPlans) (err error) {
|
||||
if len(ats) == 0 {
|
||||
// delete the key
|
||||
delete(ms.dict, utils.ACTION_PLAN_PREFIX+key)
|
||||
cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
|
||||
return
|
||||
}
|
||||
result, err := ms.ms.Marshal(&ats)
|
||||
@@ -740,6 +741,11 @@ func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetDerivedChargers(key string, dcs utils.DerivedChargers) error {
|
||||
if len(dcs) == 0 {
|
||||
delete(ms.dict, utils.DERIVEDCHARGERS_PREFIX+key)
|
||||
cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
|
||||
return nil
|
||||
}
|
||||
result, err := ms.ms.Marshal(dcs)
|
||||
ms.dict[utils.DERIVEDCHARGERS_PREFIX+key] = result
|
||||
return err
|
||||
|
||||
@@ -1077,6 +1077,14 @@ func (ms *MongoStorage) GetActionPlans(key string, skipCache bool) (ats ActionPl
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetActionPlans(key string, ats ActionPlans) error {
|
||||
if len(ats) == 0 {
|
||||
cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
|
||||
err := ms.db.C(colApl).Remove(bson.M{"key": key})
|
||||
if err != mgo.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
_, err := ms.db.C(colApl).Upsert(bson.M{"key": key}, &struct {
|
||||
Key string
|
||||
Value ActionPlans
|
||||
@@ -1121,8 +1129,8 @@ func (ms *MongoStorage) GetDerivedChargers(key string, skipCache bool) (dcs util
|
||||
|
||||
func (ms *MongoStorage) SetDerivedChargers(key string, dcs utils.DerivedChargers) (err error) {
|
||||
if len(dcs) == 0 {
|
||||
err = ms.db.C(colDcs).Remove(bson.M{"key": key})
|
||||
cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
|
||||
err = ms.db.C(colDcs).Remove(bson.M{"key": key})
|
||||
if err != mgo.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -873,6 +873,7 @@ func (rs *RedisStorage) SetActionPlans(key string, ats ActionPlans) (err error)
|
||||
if len(ats) == 0 {
|
||||
// delete the key
|
||||
_, err = rs.db.Del(utils.ACTION_PLAN_PREFIX + key)
|
||||
cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
|
||||
return err
|
||||
}
|
||||
result, err := rs.ms.Marshal(&ats)
|
||||
@@ -918,7 +919,7 @@ func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs util
|
||||
func (rs *RedisStorage) SetDerivedChargers(key string, dcs utils.DerivedChargers) (err error) {
|
||||
if len(dcs) == 0 {
|
||||
_, err = rs.db.Del(utils.DERIVEDCHARGERS_PREFIX + key)
|
||||
// FIXME: Does cache need cleanup too?
|
||||
cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
|
||||
return err
|
||||
}
|
||||
marshaled, err := rs.ms.Marshal(dcs)
|
||||
|
||||
Reference in New Issue
Block a user