mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
Updated GetIndexes
This commit is contained in:
committed by
Dan Christian Bogos
parent
b10f779ac8
commit
180182a264
@@ -3286,20 +3286,17 @@ func (dm *DataManager) GetIndexes(idxItmType, tntCtx, idxKey string) (indexes ma
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
if x, ok := Cache.Get(idxItmType, tntCtx); ok { // Attempt to find in cache first
|
||||
if x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
indexes = x.(map[string]utils.StringSet)
|
||||
if idxKey == utils.EmptyString { // in case of empty key we expect all indexes for tenant:context
|
||||
return
|
||||
}
|
||||
indx, has := indexes[idxKey]
|
||||
if has {
|
||||
if indx == nil {
|
||||
var cachekey string
|
||||
if idxKey != utils.EmptyString {
|
||||
cachekey = utils.ConcatenatedKey(tntCtx, idxKey)
|
||||
|
||||
if x, ok := Cache.Get(idxItmType, cachekey); ok { // Attempt to find in cache first
|
||||
if x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return map[string]utils.StringSet{idxKey: indx}, nil
|
||||
return map[string]utils.StringSet{
|
||||
idxKey: x.(utils.StringSet),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
if indexes, err = dm.DataDB().GetIndexesDrv(idxItmType, tntCtx, idxKey); err != nil {
|
||||
@@ -3323,18 +3320,8 @@ func (dm *DataManager) GetIndexes(idxItmType, tntCtx, idxKey string) (indexes ma
|
||||
// if err != nil {
|
||||
// err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound {
|
||||
if idxKey == utils.EmptyString {
|
||||
if errCh := Cache.Set(idxItmType, tntCtx, nil, nil,
|
||||
true, utils.NonTransactional); errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
} else {
|
||||
idx := make(map[string]utils.StringSet)
|
||||
if x, ok := Cache.Get(idxItmType, tntCtx); ok && x != nil {
|
||||
idx = x.(map[string]utils.StringSet)
|
||||
}
|
||||
idx[idxKey] = nil
|
||||
if errCh := Cache.Set(idxItmType, tntCtx, idx, nil,
|
||||
if idxKey != utils.EmptyString {
|
||||
if errCh := Cache.Set(idxItmType, cachekey, nil, nil,
|
||||
true, utils.NonTransactional); errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
@@ -3343,17 +3330,14 @@ func (dm *DataManager) GetIndexes(idxItmType, tntCtx, idxKey string) (indexes ma
|
||||
return nil, err
|
||||
// }
|
||||
}
|
||||
idx := make(map[string]utils.StringSet)
|
||||
if x, ok := Cache.Get(idxItmType, tntCtx); ok && x != nil {
|
||||
idx = x.(map[string]utils.StringSet)
|
||||
}
|
||||
|
||||
for k, v := range indexes {
|
||||
idx[k] = v
|
||||
}
|
||||
if err = Cache.Set(idxItmType, tntCtx, idx, nil,
|
||||
true, utils.NonTransactional); err != nil {
|
||||
return nil, err
|
||||
if err = Cache.Set(idxItmType, utils.ConcatenatedKey(tntCtx, k), v, []string{tntCtx},
|
||||
true, utils.NonTransactional); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -1447,27 +1448,32 @@ func (iDB *InternalDB) RemoveLoadIDsDrv() (err error) {
|
||||
}
|
||||
|
||||
func (iDB *InternalDB) GetIndexesDrv(idxItmType, tntCtx, idxKey string) (indexes map[string]utils.StringSet, err error) {
|
||||
dbKey := utils.CacheInstanceToPrefix[idxItmType] + tntCtx
|
||||
if idxKey == utils.EmptyString { // return all
|
||||
indexes = make(map[string]utils.StringSet)
|
||||
for _, dbKey := range iDB.db.GetGroupItemIDs(idxItmType, tntCtx) {
|
||||
x, ok := iDB.db.Get(idxItmType, dbKey)
|
||||
if !ok || x == nil {
|
||||
continue
|
||||
}
|
||||
dbKey = strings.TrimPrefix(dbKey, tntCtx+utils.CONCATENATED_KEY_SEP)
|
||||
indexes[dbKey] = x.(utils.StringSet).Clone()
|
||||
}
|
||||
return
|
||||
}
|
||||
dbKey := utils.ConcatenatedKey(tntCtx, idxKey)
|
||||
x, ok := iDB.db.Get(idxItmType, dbKey)
|
||||
if !ok || x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
indexes = x.(map[string]utils.StringSet)
|
||||
if len(idxKey) != 0 {
|
||||
return map[string]utils.StringSet{
|
||||
idxKey: indexes[idxKey].Clone(),
|
||||
}, nil
|
||||
}
|
||||
if len(indexes) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return map[string]utils.StringSet{
|
||||
idxKey: x.(utils.StringSet).Clone(),
|
||||
}, nil
|
||||
return
|
||||
}
|
||||
|
||||
func (iDB *InternalDB) SetIndexesDrv(idxItmType, tntCtx string,
|
||||
indexes map[string]utils.StringSet, commit bool, transactionID string) (err error) {
|
||||
originKey := utils.CacheInstanceToPrefix[idxItmType] + tntCtx
|
||||
dbKey := originKey
|
||||
dbKey := tntCtx
|
||||
if transactionID != "" {
|
||||
dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID)
|
||||
}
|
||||
@@ -1475,7 +1481,7 @@ func (iDB *InternalDB) SetIndexesDrv(idxItmType, tntCtx string,
|
||||
x, _ := iDB.db.Get(idxItmType, dbKey)
|
||||
iDB.db.Remove(idxItmType, dbKey,
|
||||
cacheCommit(utils.NonTransactional), utils.NonTransactional)
|
||||
iDB.db.Set(idxItmType, originKey, x, nil,
|
||||
iDB.db.Set(idxItmType, tntCtx, x, []string{tntCtx},
|
||||
cacheCommit(utils.NonTransactional), utils.NonTransactional)
|
||||
return
|
||||
}
|
||||
@@ -1493,7 +1499,7 @@ func (iDB *InternalDB) SetIndexesDrv(idxItmType, tntCtx string,
|
||||
|
||||
x, ok := iDB.db.Get(idxItmType, dbKey)
|
||||
if !ok || x == nil {
|
||||
iDB.db.Set(idxItmType, dbKey, toBeAdded, nil,
|
||||
iDB.db.Set(idxItmType, dbKey, toBeAdded, []string{tntCtx},
|
||||
cacheCommit(utils.NonTransactional), utils.NonTransactional)
|
||||
return err
|
||||
}
|
||||
@@ -1508,12 +1514,11 @@ func (iDB *InternalDB) SetIndexesDrv(idxItmType, tntCtx string,
|
||||
}
|
||||
mp[key] = strMp
|
||||
}
|
||||
iDB.db.Set(idxItmType, dbKey, mp, nil,
|
||||
iDB.db.Set(idxItmType, dbKey, mp, []string{tntCtx},
|
||||
cacheCommit(transactionID), transactionID)
|
||||
return nil
|
||||
}
|
||||
func (iDB *InternalDB) RemoveIndexesDrv(idxItmType, tntCtx string) (err error) {
|
||||
iDB.db.Remove(idxItmType, utils.CacheInstanceToPrefix[idxItmType]+tntCtx,
|
||||
cacheCommit(utils.NonTransactional), utils.NonTransactional)
|
||||
iDB.db.Remove(idxItmType, tntCtx, cacheCommit(utils.NonTransactional), utils.NonTransactional)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1783,7 +1783,7 @@ func (rs *RedisStorage) GetIndexesDrv(idxItmType, tntCtx, idxKey string) (indexe
|
||||
|
||||
// SetFilterIndexesDrv stores Indexes into DataDB
|
||||
func (rs *RedisStorage) SetIndexesDrv(idxItmType, tntCtx string,
|
||||
indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) {
|
||||
indexes map[string]utils.StringSet, commit bool, transactionID string) (err error) {
|
||||
originKey := utils.CacheInstanceToPrefix[idxItmType] + tntCtx
|
||||
dbKey := originKey
|
||||
if transactionID != "" {
|
||||
|
||||
Reference in New Issue
Block a user