diff --git a/apier/v1/apier.go b/apier/v1/apier.go index fe83aafb1..0a04b5f08 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -22,7 +22,6 @@ import ( "encoding/json" "errors" "fmt" - "log" "path" "github.com/cgrates/cgrates/cache2go" @@ -793,11 +792,9 @@ func (self *ApierV1) ReloadCache(attrs utils.ApiReloadCache, reply *string) erro dcsKeys[idx] = engine.DERIVEDCHARGERS_PREFIX + dc } } - log.Print("Cache Rating") if err := self.RatingDb.CacheRating(dstKeys, rpKeys, rpfKeys, rpAlsKeys, lcrKeys); err != nil { return err } - log.Print("Cache Accounting") if err := self.AccountDb.CacheAccounting(actKeys, shgKeys, accAlsKeys, dcsKeys); err != nil { return err } diff --git a/engine/destinations.go b/engine/destinations.go index 993ff301f..770f7354b 100644 --- a/engine/destinations.go +++ b/engine/destinations.go @@ -91,10 +91,9 @@ func CleanStalePrefixes(destIds []string) { } for prefix, idIDs := range prefixMap { dIDs := idIDs.Value().([]interface{}) - strdIDs := utils.ConvertInterfaceSliceToStringMap(dIDs) changed := false for _, searchedDID := range destIds { - if i, found := strdIDs[searchedDID]; found { + if i, found := utils.GetSliceInterfaceIndex(dIDs, searchedDID); found { if len(dIDs) == 1 { // remove de prefix from cache cache2go.RemKey(DESTINATION_PREFIX + prefix) diff --git a/utils/slice.go b/utils/slice.go index bec15c525..1e1bb7879 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -52,10 +52,18 @@ func SliceMemberHasPrefix(ss []string, prfx string) bool { return false } -func ConvertInterfaceSliceToStringMap(is []interface{}) (result map[string]int) { - result = make(map[string]int) - for index, i := range is { - result[i.(string)] = index +type InterfaceStrings []interface{} + +func (a InterfaceStrings) Len() int { return len(a) } +func (a InterfaceStrings) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a InterfaceStrings) Less(i, j int) bool { return a[i].(string) < a[j].(string) } + +// Binary string search in slice +// returns true if found and the index +func GetSliceInterfaceIndex(ss []interface{}, s interface{}) (int, bool) { + sort.Sort(InterfaceStrings(ss)) + if i := sort.Search(len(ss), func(i int) bool { return ss[i].(string) >= s.(string) }); i < len(ss) && ss[i] == s { + return i, true } - return result + return len(ss), false }