mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
using destination id in revers aliases
This commit is contained in:
@@ -562,6 +562,7 @@ func (ms *MapStorage) SetAlias(al *Alias) error {
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error) {
|
||||
origKey := key
|
||||
key = utils.ALIASES_PREFIX + key
|
||||
if !skipCache {
|
||||
if x, err := cache2go.GetCached(key); err == nil {
|
||||
@@ -586,7 +587,7 @@ func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error
|
||||
} else {
|
||||
existingKeys = make(map[string]bool)
|
||||
}
|
||||
existingKeys[key] = true
|
||||
existingKeys[utils.ConcatenatedKey(origKey, v.DestinationId)] = true
|
||||
cache2go.Cache(rKey, existingKeys)
|
||||
}
|
||||
}
|
||||
@@ -599,6 +600,7 @@ func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error
|
||||
func (ms *MapStorage) RemoveAlias(key string) error {
|
||||
al := &Alias{}
|
||||
al.SetId(key)
|
||||
origKey := key
|
||||
key = utils.ALIASES_PREFIX + key
|
||||
aliasValues := make(AliasValues, 0)
|
||||
if values, ok := ms.dict[key]; ok {
|
||||
@@ -611,10 +613,14 @@ func (ms *MapStorage) RemoveAlias(key string) error {
|
||||
if x, err := cache2go.GetCached(rKey); err == nil {
|
||||
existingKeys = x.(map[string]bool)
|
||||
}
|
||||
if len(existingKeys) == 1 {
|
||||
for eKey := range existingKeys {
|
||||
if strings.HasPrefix(eKey, origKey) {
|
||||
delete(existingKeys, eKey)
|
||||
}
|
||||
}
|
||||
if len(existingKeys) == 0 {
|
||||
cache2go.RemKey(rKey)
|
||||
} else {
|
||||
delete(existingKeys, key)
|
||||
cache2go.Cache(rKey, existingKeys)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"compress/zlib"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -665,6 +666,7 @@ func (rs *RedisStorage) SetAlias(al *Alias) (err error) {
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err error) {
|
||||
origKey := key
|
||||
key = utils.ALIASES_PREFIX + key
|
||||
if !skipCache {
|
||||
if x, err := cache2go.GetCached(key); err == nil {
|
||||
@@ -691,7 +693,7 @@ func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err err
|
||||
} else {
|
||||
existingKeys = make(map[string]bool)
|
||||
}
|
||||
existingKeys[key] = true
|
||||
existingKeys[utils.ConcatenatedKey(origKey, v.DestinationId)] = true
|
||||
cache2go.Cache(rKey, existingKeys)
|
||||
}
|
||||
}
|
||||
@@ -702,6 +704,7 @@ func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err err
|
||||
func (rs *RedisStorage) RemoveAlias(key string) (err error) {
|
||||
al := &Alias{}
|
||||
al.SetId(key)
|
||||
origKey := key
|
||||
key = utils.ALIASES_PREFIX + key
|
||||
aliasValues := make(AliasValues, 0)
|
||||
if values, err := rs.db.Get(key); err == nil {
|
||||
@@ -715,10 +718,14 @@ func (rs *RedisStorage) RemoveAlias(key string) (err error) {
|
||||
if x, err := cache2go.GetCached(rKey); err == nil {
|
||||
existingKeys = x.(map[string]bool)
|
||||
}
|
||||
if len(existingKeys) == 1 {
|
||||
for eKey := range existingKeys {
|
||||
if strings.HasPrefix(eKey, origKey) {
|
||||
delete(existingKeys, eKey)
|
||||
}
|
||||
}
|
||||
if len(existingKeys) == 0 {
|
||||
cache2go.RemKey(rKey)
|
||||
} else {
|
||||
delete(existingKeys, key)
|
||||
cache2go.Cache(rKey, existingKeys)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,16 +181,16 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
|
||||
}
|
||||
if x, err := cache2go.GetCached(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_GROUP_RP); err == nil {
|
||||
aliasKeys := x.(map[string]bool)
|
||||
_, found := aliasKeys[utils.ALIASES_PREFIX+ala.GetId()]
|
||||
_, found := aliasKeys[utils.ConcatenatedKey(ala.GetId(), utils.ANY)]
|
||||
if !found {
|
||||
t.Error("Error getting reverse alias: ", aliasKeys)
|
||||
t.Error("Error getting reverse alias: ", aliasKeys, ala.GetId()+utils.ANY)
|
||||
}
|
||||
} else {
|
||||
t.Error("Error getting reverse alias: ", err)
|
||||
}
|
||||
if x, err := cache2go.GetCached(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_GROUP_ACC); err == nil {
|
||||
aliasKeys := x.(map[string]bool)
|
||||
_, found := aliasKeys[utils.ALIASES_PREFIX+alb.GetId()]
|
||||
_, found := aliasKeys[utils.ConcatenatedKey(alb.GetId(), utils.ANY)]
|
||||
if !found {
|
||||
t.Error("Error getting reverse alias: ", aliasKeys)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user