mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 21:29:52 +05:00
Updated checking dynamic path for filters
This commit is contained in:
committed by
Dan Christian Bogos
parent
9b29d775e8
commit
e36d56e953
@@ -120,20 +120,14 @@ func (admS *AdminSv1) composeArgsReload(ctx *context.Context, tnt, cacheID, item
|
||||
return
|
||||
}
|
||||
for _, flt := range fltr.Rules {
|
||||
if !engine.FilterIndexTypes.Has(flt.Type) {
|
||||
if !engine.FilterIndexTypes.Has(flt.Type) ||
|
||||
engine.IsDynamicDPPath(flt.Element) {
|
||||
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 engine.IsDynamicDPPath(fldVal) {
|
||||
continue
|
||||
}
|
||||
if isDyn {
|
||||
if !strings.HasPrefix(fldVal, utils.DynamicDataPrefix) {
|
||||
@@ -282,20 +276,14 @@ func (apierSv1 *AdminS) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs
|
||||
func composeCacheArgsForFilter(dm *engine.DataManager, ctx *context.Context, fltr *engine.Filter, tnt, tntID string, args map[string][]string) (_ map[string][]string, err error) {
|
||||
indxIDs := make([]string, 0, len(fltr.Rules))
|
||||
for _, flt := range fltr.Rules {
|
||||
if !engine.FilterIndexTypes.Has(flt.Type) {
|
||||
if !engine.FilterIndexTypes.Has(flt.Type) ||
|
||||
engine.IsDynamicDPPath(flt.Element) {
|
||||
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 engine.IsDynamicDPPath(fldVal) {
|
||||
continue
|
||||
}
|
||||
if isDyn {
|
||||
if !strings.HasPrefix(fldVal, utils.DynamicDataPrefix) {
|
||||
|
||||
@@ -31,6 +31,12 @@ import (
|
||||
|
||||
var (
|
||||
FilterIndexTypes = utils.NewStringSet([]string{utils.MetaPrefix, utils.MetaString, utils.MetaSuffix})
|
||||
// Element or values of a filter that starts with one of this should not be indexed
|
||||
ToNotBeIndexed = []string{utils.DynamicDataPrefix + utils.MetaAccounts,
|
||||
utils.DynamicDataPrefix + utils.MetaStats,
|
||||
utils.DynamicDataPrefix + utils.MetaResources,
|
||||
utils.DynamicDataPrefix + utils.MetaLibPhoneNumber,
|
||||
utils.DynamicDataPrefix + utils.MetaAsm}
|
||||
)
|
||||
|
||||
// newFilterIndex will get the index from DataManager if is not found it will create it
|
||||
@@ -74,22 +80,16 @@ func newFilterIndex(apiCtx *context.Context, dm *DataManager, idxItmType, tnt, c
|
||||
return
|
||||
}
|
||||
for _, flt := range fltr.Rules {
|
||||
if !FilterIndexTypes.Has(flt.Type) {
|
||||
if !FilterIndexTypes.Has(flt.Type) ||
|
||||
IsDynamicDPPath(flt.Element) {
|
||||
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) {
|
||||
for _, fldVal := range flt.Values {
|
||||
if IsDynamicDPPath(fldVal) {
|
||||
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
|
||||
@@ -530,22 +530,16 @@ func UpdateFilterIndex(apiCtx *context.Context, dm *DataManager, oldFlt, newFlt
|
||||
newRules := utils.StringSet{} // we only need to determine if we added new rules to rebuild
|
||||
removeRules := utils.StringSet{} // but we need to know what indexes to remove
|
||||
for _, flt := range newFlt.Rules {
|
||||
if !FilterIndexTypes.Has(flt.Type) {
|
||||
if !FilterIndexTypes.Has(flt.Type) ||
|
||||
IsDynamicDPPath(flt.Element) {
|
||||
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) {
|
||||
for _, fldVal := range flt.Values {
|
||||
if IsDynamicDPPath(fldVal) {
|
||||
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
|
||||
@@ -561,11 +555,15 @@ func UpdateFilterIndex(apiCtx *context.Context, dm *DataManager, oldFlt, newFlt
|
||||
}
|
||||
}
|
||||
for _, flt := range oldFlt.Rules {
|
||||
if !FilterIndexTypes.Has(flt.Type) {
|
||||
if !FilterIndexTypes.Has(flt.Type) ||
|
||||
IsDynamicDPPath(flt.Element) {
|
||||
continue
|
||||
}
|
||||
isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix)
|
||||
for _, fldVal := range flt.Values {
|
||||
if IsDynamicDPPath(fldVal) {
|
||||
continue
|
||||
}
|
||||
var idxKey string
|
||||
if isDyn {
|
||||
if strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { // do not index if both the element and the value is dynamic
|
||||
@@ -908,3 +906,14 @@ func removeFilterIndexesForFilter(ctx *context.Context, dm *DataManager, idxItmT
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IsDynamicDPPath check dynamic path with ~*stats, ~*resources, ~*accounts, ~*libphonenumber, ~*asm to not be indexed
|
||||
// Used to determine if the rule will be indexed
|
||||
func IsDynamicDPPath(path string) bool {
|
||||
for _, notIndex := range ToNotBeIndexed {
|
||||
if strings.HasPrefix(path, notIndex) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -144,12 +144,6 @@ var (
|
||||
TBLTPAccounts: CacheTBLTPAccounts,
|
||||
}
|
||||
|
||||
// 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})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user