From c2cb492cbeb675bd54bcc427a524ae45ff0f0bd6 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 4 Sep 2015 13:49:35 +0300 Subject: [PATCH] started liases reverse mapping --- engine/storage_map.go | 9 +++++++++ engine/storage_redis.go | 10 ++++++++++ utils/consts.go | 1 + 3 files changed, 20 insertions(+) diff --git a/engine/storage_map.go b/engine/storage_map.go index d69092d3f..1982b2b9a 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -578,6 +578,15 @@ func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error err = ms.ms.Unmarshal(values, &al.Values) if err == nil { cache2go.Cache(key, al.Values) + for _, v := range al.Values { + var existingKeys []string + rKey := utils.REVERSE_ALIASES_PREFIX + v.Alias + if x, err := cache2go.GetCached(rKey); err == nil { + existingKeys = x.([]string) + } + existingKeys = append(existingKeys, key) + cache2go.Cache(rKey, existingKeys) + } } } else { return nil, utils.ErrNotFound diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 1eeda1d2a..92e37a2e9 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -682,6 +682,16 @@ func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err err err = rs.ms.Unmarshal(values, &al.Values) if err == nil { cache2go.Cache(key, al.Values) + // cache reverse alias + for _, v := range al.Values { + var existingKeys []string + rKey := utils.REVERSE_ALIASES_PREFIX + v.Alias + if x, err := cache2go.GetCached(rKey); err == nil { + existingKeys = x.([]string) + } + existingKeys = append(existingKeys, key) + cache2go.Cache(rKey, existingKeys) + } } } return diff --git a/utils/consts.go b/utils/consts.go index 42548a621..cc5a07d0b 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -176,6 +176,7 @@ const ( PUBSUB_SUBSCRIBERS_PREFIX = "pss_" USERS_PREFIX = "usr_" ALIASES_PREFIX = "als_" + REVERSE_ALIASES_PREFIX = "rls_" CDR_STATS_PREFIX = "cst_" TEMP_DESTINATION_PREFIX = "tmp_" LOG_CALL_COST_PREFIX = "cco_"