mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
another optimization for stale dest ids
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user