From c9341ff3de15a92e814eb6433027b6915d9d1052 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Wed, 26 May 2021 11:00:13 +0300 Subject: [PATCH] *accounts, *stats, *resources, *libphnumber are not indexing --- apier/v1/libapier.go | 20 ++++++++++++++++++++ engine/libindex.go | 21 ++++++++++++++++++++- utils/consts.go | 7 +++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/apier/v1/libapier.go b/apier/v1/libapier.go index 00fba905f..7a1cee938 100644 --- a/apier/v1/libapier.go +++ b/apier/v1/libapier.go @@ -123,7 +123,17 @@ func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterI continue } isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) + for _, notIndex := range utils.ToNotBeIndexed { // element with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(flt.Element, notIndex) { + continue + } + } for _, fldVal := range flt.Values { + for _, notIndex := range utils.ToNotBeIndexed { // value with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(fldVal, notIndex) { + continue + } + } if isDyn { if !strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { indxIDs = append(indxIDs, utils.ConcatenatedKey(flt.Type, flt.Element[1:], fldVal)) @@ -273,7 +283,17 @@ func composeCacheArgsForFilter(dm *engine.DataManager, fltr *engine.Filter, tnt, continue } isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) + for _, notIndex := range utils.ToNotBeIndexed { // element with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(flt.Element, notIndex) { + continue + } + } for _, fldVal := range flt.Values { + for _, notIndex := range utils.ToNotBeIndexed { // value with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(fldVal, notIndex) { + continue + } + } if isDyn { if !strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { indxIDs = append(indxIDs, utils.ConcatenatedKey(flt.Type, flt.Element[1:], fldVal)) diff --git a/engine/libindex.go b/engine/libindex.go index 25fc978c7..908414fc7 100644 --- a/engine/libindex.go +++ b/engine/libindex.go @@ -75,10 +75,19 @@ func newFilterIndex(dm *DataManager, idxItmType, tnt, ctx, itemID string, filter if !FilterIndexTypes.Has(flt.Type) { continue } - isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) + for _, notIndex := range utils.ToNotBeIndexed { // element with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(flt.Element, notIndex) { + continue + } + } for _, fldVal := range flt.Values { var idxKey string + for _, notIndex := range utils.ToNotBeIndexed { // value with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(fldVal, notIndex) { + continue + } + } if isDyn { if strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { // do not index if both the element and the value is dynamic continue @@ -521,8 +530,18 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) { continue } isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) + for _, notIndex := range utils.ToNotBeIndexed { // element with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(flt.Element, notIndex) { + continue + } + } for _, fldVal := range flt.Values { var idxKey string + for _, notIndex := range utils.ToNotBeIndexed { // value with ~*stats, ~*resources, ~*accounts, ~*libphonenumber to not be indexed + if strings.HasPrefix(flt.Element, notIndex) { + continue + } + } if isDyn { if strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { // do not index if both the element and the value is dynamic continue diff --git a/utils/consts.go b/utils/consts.go index 95d6bf6cb..4f597d7af 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -156,6 +156,13 @@ var ( TBLTPDispatchers: CacheTBLTPDispatchers, TBLTPDispatcherHosts: CacheTBLTPDispatcherHosts, } + + // Element or values of a filter that starts with one of this should not be indexed + ToNotBeIndexed = []string{DynamicDataPrefix + MetaAccounts, + DynamicDataPrefix + MetaStats, + DynamicDataPrefix + MetaResources, + DynamicDataPrefix + MetaLibPhoneNumber} + // ProtectedSFlds are the fields that sessions should not alter ProtectedSFlds = NewStringSet([]string{CGRID, OriginHost, OriginID, Usage}) ArgCacheToPrefix = map[string]string{