New cases in updating indexes for new susbsystem's profiles

This commit is contained in:
porosnicuadrian
2021-03-09 17:55:20 +02:00
committed by Dan Christian Bogos
parent 993231f336
commit 5cc52cb490
3 changed files with 64 additions and 6 deletions

View File

@@ -226,7 +226,7 @@ func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFil
return
}
// updatedIndexesWithContexts will compare the old contexts with the new ones and only uptdate what is needed
// 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)
func updatedIndexesWithContexts(dm *DataManager, idxItmType, tnt, itemID string,
oldContexts, oldFilterIDs *[]string, newContexts, newFilterIDs []string) (err error) {
@@ -673,6 +673,66 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) {
}); err != nil && err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheAccountProfilesFilterIndexes:
if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
removeIndexKeys, indx); err != nil {
return
}
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
ap, e := dm.GetAccountProfile(tnt, id)
if e != nil {
return nil, e
}
fltrIDs := make([]string, len(ap.FilterIDs))
for i, fltrID := range ap.FilterIDs {
fltrIDs[i] = fltrID
}
return &fltrIDs, nil
}); err != nil && err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheActionProfilesFilterIndexes:
if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
removeIndexKeys, indx); err != nil {
return
}
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
acp, e := dm.GetActionProfile(tnt, id, true, false, utils.NonTransactional)
if e != nil {
return nil, e
}
fltrIDs := make([]string, len(acp.FilterIDs))
for i, fltrID := range acp.FilterIDs {
fltrIDs[i] = fltrID
}
return &fltrIDs, nil
}); err != nil || err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheRateProfilesFilterIndexes:
if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
removeIndexKeys, indx); err != nil {
return
}
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
rp, e := dm.GetRateProfile(tnt, id, true, false, utils.NonTransactional)
if e != nil {
return nil, e
}
fltrIDs := make([]string, len(rp.FilterIDs))
for i, fltrID := range rp.FilterIDs {
fltrIDs[i] = fltrID
}
return &fltrIDs, nil
}); err != nil || err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheAttributeFilterIndexes:
for itemID := range indx {
var ap *AttributeProfile