From 30a842a6b9fffe536b04d66ad3f508dc0bb9ec53 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Sat, 1 Feb 2014 14:04:12 +0200 Subject: [PATCH] miminmum match length is now parametrized and can be moved in the confs Note that it affects the general speed --- engine/calldesc.go | 2 ++ engine/ratingprofile.go | 2 +- engine/units_counter.go | 2 +- engine/userbalance.go | 2 +- utils/coreutils.go | 4 ++-- utils/utils_test.go | 11 +++++++++-- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/engine/calldesc.go b/engine/calldesc.go index bc98fd80c..769598d3d 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -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 ) diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index 12bd6ea5e..8bc32afc6 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -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 { diff --git a/engine/units_counter.go b/engine/units_counter.go index 3adc1c605..42742f6c9 100644 --- a/engine/units_counter.go +++ b/engine/units_counter.go @@ -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 { diff --git a/engine/userbalance.go b/engine/userbalance.go index a135f5b27..49f97f67e 100644 --- a/engine/userbalance.go +++ b/engine/userbalance.go @@ -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 { diff --git a/utils/coreutils.go b/utils/coreutils.go index ff13e9fce..cf1fce232 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -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++ { diff --git a/utils/utils_test.go b/utils/utils_test.go index c7ab8de1b..676824f70 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -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) }