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:
Radu Ioan Fericean
2014-02-01 14:04:12 +02:00
parent 750260505c
commit 30a842a6b9
6 changed files with 16 additions and 7 deletions

View File

@@ -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
)

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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++ {

View File

@@ -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)
}