using destination id in revers aliases

This commit is contained in:
Radu Ioan Fericean
2015-09-04 17:34:51 +03:00
parent 0a1fc7d96d
commit eb182825ed
3 changed files with 22 additions and 9 deletions

View File

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

View File

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

View File

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