Updated the reverse filter indexing for the rates from RateProfiles

This commit is contained in:
Trial97
2021-03-10 11:08:39 +02:00
committed by Dan Christian Bogos
parent 1c69343c21
commit a2c7c7447d
2 changed files with 33 additions and 14 deletions

View File

@@ -1133,7 +1133,7 @@ func (dm *DataManager) SetThresholdProfile(th *ThresholdProfile, withIndex bool)
oldFiltersIDs = &oldTh.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheThresholdFilterIndexes, th.Tenant,
utils.EmptyString, th.ID, oldFiltersIDs, th.FilterIDs); err != nil {
utils.EmptyString, th.ID, oldFiltersIDs, th.FilterIDs, false); err != nil {
return err
}
}
@@ -1261,7 +1261,7 @@ func (dm *DataManager) SetStatQueueProfile(sqp *StatQueueProfile, withIndex bool
oldFiltersIDs = &oldSts.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheStatFilterIndexes, sqp.Tenant,
utils.EmptyString, sqp.ID, oldFiltersIDs, sqp.FilterIDs); err != nil {
utils.EmptyString, sqp.ID, oldFiltersIDs, sqp.FilterIDs, false); err != nil {
return err
}
}
@@ -1595,7 +1595,7 @@ func (dm *DataManager) SetResourceProfile(rp *ResourceProfile, withIndex bool) (
oldFiltersIDs = &oldRes.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheResourceFilterIndexes, rp.Tenant,
utils.EmptyString, rp.ID, oldFiltersIDs, rp.FilterIDs); err != nil {
utils.EmptyString, rp.ID, oldFiltersIDs, rp.FilterIDs, false); err != nil {
return err
}
Cache.Clear([]string{utils.CacheEventResources})
@@ -2416,7 +2416,7 @@ func (dm *DataManager) SetRouteProfile(rpp *RouteProfile, withIndex bool) (err e
oldFiltersIDs = &oldRpp.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheRouteFilterIndexes, rpp.Tenant,
utils.EmptyString, rpp.ID, oldFiltersIDs, rpp.FilterIDs); err != nil {
utils.EmptyString, rpp.ID, oldFiltersIDs, rpp.FilterIDs, false); err != nil {
return err
}
}
@@ -2681,7 +2681,7 @@ func (dm *DataManager) SetChargerProfile(cpp *ChargerProfile, withIndex bool) (e
oldFiltersIDs = &oldCpp.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheChargerFilterIndexes, cpp.Tenant,
utils.EmptyString, cpp.ID, oldFiltersIDs, cpp.FilterIDs); err != nil {
utils.EmptyString, cpp.ID, oldFiltersIDs, cpp.FilterIDs, false); err != nil {
return err
}
}
@@ -3115,7 +3115,7 @@ func (dm *DataManager) SetRateProfile(rpp *RateProfile, withIndex bool) (err err
oldFiltersIDs = &oldRpp.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheRateProfilesFilterIndexes, rpp.Tenant,
utils.EmptyString, rpp.ID, oldFiltersIDs, rpp.FilterIDs); err != nil {
utils.EmptyString, rpp.ID, oldFiltersIDs, rpp.FilterIDs, false); err != nil {
return err
}
// remove indexes for old rates
@@ -3140,7 +3140,7 @@ func (dm *DataManager) SetRateProfile(rpp *RateProfile, withIndex bool) (err err
}
// when we create the indexes for rates we use RateProfile ID as context
if err := updatedIndexes(dm, utils.CacheRateFilterIndexes, rpp.Tenant,
rpp.ID, key, oldRateFiltersIDs, rate.FilterIDs); err != nil {
rpp.ID, key, oldRateFiltersIDs, rate.FilterIDs, true); err != nil {
return err
}
}
@@ -3275,7 +3275,7 @@ func (dm *DataManager) SetRateProfileRates(rpp *RateProfile, withIndex bool) (er
}
// when we create the indexes for rates we use RateProfile ID as context
if err := updatedIndexes(dm, utils.CacheRateFilterIndexes, rpp.Tenant,
rpp.ID, key, oldRateFiltersIDs, rate.FilterIDs); err != nil {
rpp.ID, key, oldRateFiltersIDs, rate.FilterIDs, true); err != nil {
return err
}
}
@@ -3373,7 +3373,7 @@ func (dm *DataManager) SetActionProfile(ap *ActionProfile, withIndex bool) (err
oldFiltersIDs = &oldRpp.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheActionProfilesFilterIndexes, ap.Tenant,
utils.EmptyString, ap.ID, oldFiltersIDs, ap.FilterIDs); err != nil {
utils.EmptyString, ap.ID, oldFiltersIDs, ap.FilterIDs, false); err != nil {
return err
}
}
@@ -3668,7 +3668,7 @@ func (dm *DataManager) SetAccountProfile(ap *utils.AccountProfile, withIndex boo
oldFiltersIDs = &oldRpp.FilterIDs
}
if err := updatedIndexes(dm, utils.CacheAccountProfilesFilterIndexes, ap.Tenant,
utils.EmptyString, ap.ID, oldFiltersIDs, ap.FilterIDs); err != nil {
utils.EmptyString, ap.ID, oldFiltersIDs, ap.FilterIDs, false); err != nil {
return err
}
}

View File

@@ -172,9 +172,21 @@ func removeItemFromFilterIndex(dm *DataManager, idxItmType, tnt, ctx, itemID str
}
// updatedIndexes will compare the old filtersIDs with the new ones and only update the filters indexes that are added/removed
func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFilterIds *[]string, newFilterIDs []string) (err error) {
// idxItmType - the index object type(e.g.*attribute_filter_indexes, *rate_filter_indexes, *threshold_filter_indexes)
// tnt - the tenant of the object
// ctx - the rate profile id for rate from RateProfile(sub indexes); for all the rest the ctx is ""(AttributePrf and DispatcherPrf have a separate function)
// itemID - the object id
// oldFilterIds - the filtersIDs that the old object had; this is optional if the object did not exist
// newFilterIDs - the filtersIDs for the object that will be set
// useCtx - in case of subindexes(e.g. Rate from RateProfiles) need to add the ctx to the itemID when reverse filter indexes are set
// used when updating the filters
func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFilterIds *[]string, newFilterIDs []string, useCtx bool) (err error) {
itmCtx := itemID
if useCtx {
itmCtx = utils.ConcatenatedKey(itemID, ctx)
}
if oldFilterIds == nil { // nothing to remove so just create the new indexes
if err = addIndexFiltersItem(dm, idxItmType, tnt, itemID, newFilterIDs); err != nil {
if err = addIndexFiltersItem(dm, idxItmType, tnt, itmCtx, newFilterIDs); err != nil {
return
}
return addItemToFilterIndex(dm, idxItmType, tnt, ctx, itemID, newFilterIDs)
@@ -205,7 +217,7 @@ func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFil
if len(oldFilterIDs) != 0 || oldFltrs.Size() == 0 {
// has some indexes to remove or
// the old profile doesn't have filters but the new one has so remove the *none index
if err = removeIndexFiltersItem(dm, idxItmType, tnt, itemID, oldFilterIDs); err != nil {
if err = removeIndexFiltersItem(dm, idxItmType, tnt, itmCtx, oldFilterIDs); err != nil {
return
}
if err = removeItemFromFilterIndex(dm, idxItmType, tnt, ctx, itemID, oldFilterIDs); err != nil {
@@ -216,7 +228,7 @@ func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFil
if len(newFilterIDs) != 0 || newFltrs.Size() == 0 {
// has some indexes to add or
// the old profile has filters but the new one does not so add the *none index
if err = addIndexFiltersItem(dm, idxItmType, tnt, itemID, newFilterIDs); err != nil {
if err = addIndexFiltersItem(dm, idxItmType, tnt, itmCtx, newFilterIDs); err != nil {
return
}
if err = addItemToFilterIndex(dm, idxItmType, tnt, ctx, itemID, newFilterIDs); err != nil {
@@ -228,6 +240,13 @@ func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFil
// updatedIndexesWithContexts will compare the old contexts with the new ones and only update what is needed
// this is used by the profiles that have context(e.g. AttributeProfile)
// idxItmType - the index object type(e.g.*attribute_filter_indexes, *rate_filter_indexes, *threshold_filter_indexes)
// tnt - the tenant of the object
// itemID - the object id
// oldContexts - the old contexts/subsystems for profile; this is optional if the object did not exist
// oldFilterIds - the filtersIDs that the old object had; this is optional if the object did not exist
// newContexts - the new contexts/subsystems for profile that will be set
// newFilterIDs - the filtersIDs for the object that will be set
func updatedIndexesWithContexts(dm *DataManager, idxItmType, tnt, itemID string,
oldContexts, oldFilterIDs *[]string, newContexts, newFilterIDs []string) (err error) {
if oldContexts == nil { // new profile add all indexes