From 5cc52cb490da7b949fa95dab8d975d89e3da5d22 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Tue, 9 Mar 2021 17:55:20 +0200 Subject: [PATCH] New cases in updating indexes for new susbsystem's profiles --- accounts/accounts_test.go | 6 ++-- apier/v1/libapier.go | 2 +- engine/libindex.go | 62 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go index be4744d46..0827824dd 100644 --- a/accounts/accounts_test.go +++ b/accounts/accounts_test.go @@ -41,7 +41,8 @@ func TestRPCCall(t *testing.T) { } } -func TestListenAndServe(t *testing.T) { +func TestShutDownCoverage(t *testing.T) { + //this is called in order to cover the ListenAndServe method cfg := config.NewDefaultCGRConfig() dm := engine.NewDataManager(nil, cfg.CacheCfg(), nil) fltr := engine.NewFilterS(cfg, nil, dm) @@ -54,11 +55,8 @@ func TestListenAndServe(t *testing.T) { stopChan <- struct{}{} }() accnts.ListenAndServe(stopChan, cfgRld) -} -func TestShutDownCoverage(t *testing.T) { //this is called in order to cover the ShutDown method - accnts := new(AccountS) accnts.Shutdown() } diff --git a/apier/v1/libapier.go b/apier/v1/libapier.go index e68e0dcdd..348377038 100644 --- a/apier/v1/libapier.go +++ b/apier/v1/libapier.go @@ -78,7 +78,7 @@ func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterI if filterIDs == nil { // in case we remove a profile we do not need to reload the indexes return } - // popultate the indexes + // populate the indexes idxCacheID := utils.CacheInstanceToArg[utils.CacheInstanceToCacheIndex[cacheID]] if len(*filterIDs) == 0 { // in case we do not have any filters reload the *none filter indexes indxID := utils.ConcatenatedKey(utils.MetaNone, utils.MetaAny, utils.MetaAny) diff --git a/engine/libindex.go b/engine/libindex.go index 63ff9b6b7..e6f59307d 100644 --- a/engine/libindex.go +++ b/engine/libindex.go @@ -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