mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
miminmum match length is now parametrized and can be moved in the confs
Note that it affects the general speed
This commit is contained in:
@@ -49,7 +49,9 @@ func init() {
|
||||
}
|
||||
|
||||
const (
|
||||
// these might be better in the confs under optimizations section
|
||||
RECURSION_MAX_DEPTH = 3
|
||||
MIN_PREFIX_MATCH = 1
|
||||
FALLBACK_SUBJECT = utils.ANY
|
||||
)
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error)
|
||||
}
|
||||
bestPrecision := 0
|
||||
var rps RateIntervalList
|
||||
for _, p := range utils.SplitPrefix(cd.Destination) {
|
||||
for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) {
|
||||
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.([]string)
|
||||
for _, dId := range destIds {
|
||||
|
||||
@@ -68,7 +68,7 @@ func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
|
||||
if !mb.HasDestination() {
|
||||
continue
|
||||
}
|
||||
for _, p := range utils.SplitPrefix(prefix) {
|
||||
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
|
||||
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.([]string)
|
||||
for _, dId := range destIds {
|
||||
|
||||
@@ -127,7 +127,7 @@ func (ub *UserBalance) getBalancesForPrefix(prefix string, balances BalanceChain
|
||||
continue
|
||||
}
|
||||
if b.DestinationId != "" && b.DestinationId != utils.ANY {
|
||||
for _, p := range utils.SplitPrefix(prefix) {
|
||||
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
|
||||
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.([]string)
|
||||
for _, dId := range destIds {
|
||||
|
||||
@@ -159,8 +159,8 @@ func RoundTo(whole, amount time.Duration) time.Duration {
|
||||
return time.Duration((w - math.Mod(a, w)) + a)
|
||||
}
|
||||
|
||||
func SplitPrefix(prefix string) []string {
|
||||
length := int(math.Max(float64(len(prefix)), 0))
|
||||
func SplitPrefix(prefix string, minLength int) []string {
|
||||
length := int(math.Max(float64(len(prefix)-(minLength-1)), 0))
|
||||
subs := make([]string, length)
|
||||
max := len(prefix)
|
||||
for i := 0; i < length; i++ {
|
||||
|
||||
@@ -294,14 +294,21 @@ func TestRound(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSplitPrefix(t *testing.T) {
|
||||
a := SplitPrefix("0123456789")
|
||||
a := SplitPrefix("0123456789", 1)
|
||||
if len(a) != 10 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitPrefixFive(t *testing.T) {
|
||||
a := SplitPrefix("0123456789", 5)
|
||||
if len(a) != 6 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitPrefixEmpty(t *testing.T) {
|
||||
a := SplitPrefix("")
|
||||
a := SplitPrefix("", 1)
|
||||
if len(a) != 0 {
|
||||
t.Error("Error splitting prefix: ", a)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user