mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Remove from config filter reverse indexes and update integration test
This commit is contained in:
committed by
Dan Christian Bogos
parent
0f8dd3754e
commit
b7ddb2c066
@@ -57,11 +57,11 @@ var sTestsFilterIndexesSV1 = []func(t *testing.T){
|
||||
testV1FIdxThirdComputeThresholdsIndexes,
|
||||
testV1FIdxRemoveThresholdProfile,
|
||||
|
||||
// testV1FIdxSetStatQueueProfileIndexes,
|
||||
// testV1FIdxComputeStatQueueProfileIndexes,
|
||||
// testV1FIdxSetSecondStatQueueProfileIndexes,
|
||||
// testV1FIdxSecondComputeStatQueueProfileIndexes,
|
||||
// testV1FIdxRemoveStatQueueProfile,
|
||||
testV1FIdxSetStatQueueProfileIndexes,
|
||||
testV1FIdxComputeStatQueueProfileIndexes,
|
||||
testV1FIdxSetSecondStatQueueProfileIndexes,
|
||||
testV1FIdxSecondComputeStatQueueProfileIndexes,
|
||||
testV1FIdxRemoveStatQueueProfile,
|
||||
|
||||
testV1FIdxSetResourceProfileIndexes,
|
||||
testV1FIdxComputeResourceProfileIndexes,
|
||||
|
||||
@@ -51,14 +51,14 @@ var sTestsFilterIndexesSV1Ca = []func(t *testing.T){
|
||||
testV1FIdxCaUpdateThresholdProfileFromTP,
|
||||
testV1FIdxCaRemoveThresholdProfile,
|
||||
|
||||
// testFlush,
|
||||
// testV1FIdxCaGetStatQueuesWithNotFound,
|
||||
// testV1FIdxCaSetStatQueueProfile,
|
||||
// testV1FIdxCaFromFolder,
|
||||
// testV1FIdxCaGetStatQueuesFromTP,
|
||||
// testV1FIdxCaUpdateStatQueueProfile,
|
||||
// testV1FIdxCaUpdateStatQueueProfileFromTP,
|
||||
// testV1FIdxCaRemoveStatQueueProfile,
|
||||
testFlush,
|
||||
testV1FIdxCaGetStatQueuesWithNotFound,
|
||||
testV1FIdxCaSetStatQueueProfile,
|
||||
testV1FIdxCaFromFolder,
|
||||
testV1FIdxCaGetStatQueuesFromTP,
|
||||
testV1FIdxCaUpdateStatQueueProfile,
|
||||
testV1FIdxCaUpdateStatQueueProfileFromTP,
|
||||
testV1FIdxCaRemoveStatQueueProfile,
|
||||
|
||||
testFlush,
|
||||
testV1FIdxCaProcessAttributeProfileEventWithNotFound,
|
||||
|
||||
@@ -190,6 +190,7 @@ func TestSSv1ItAuth(t *testing.T) {
|
||||
ID: "TestSSv1ItAuth",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.ToR: utils.VOICE,
|
||||
@@ -295,6 +296,7 @@ func TestSSv1ItInitiateSession(t *testing.T) {
|
||||
ID: "TestSSv1ItInitiateSession",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.ToR: utils.VOICE,
|
||||
@@ -391,6 +393,7 @@ func TestSSv1ItUpdateSession(t *testing.T) {
|
||||
ID: "TestSSv1ItUpdateSession",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.ToR: utils.VOICE,
|
||||
@@ -514,6 +517,7 @@ func TestSSv1ItProcessEvent(t *testing.T) {
|
||||
ID: "TestSSv1ItProcessEvent",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeeb0ab7aa7ebaf",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.ToR: utils.VOICE,
|
||||
|
||||
@@ -135,17 +135,11 @@ const CGRATES_CFG_JSON = `
|
||||
"attribute_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control attribute profile caching
|
||||
"charger_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control charger profile caching
|
||||
"resource_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control resource filter indexes caching
|
||||
"resource_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control resource filter reverse indexes caching
|
||||
"stat_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control stat filter indexes caching
|
||||
"stat_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control stat filter reverse indexes caching
|
||||
"threshold_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control threshold filter indexes caching
|
||||
"threshold_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control threshold filter reverse indexes caching
|
||||
"supplier_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control supplier filter indexes caching
|
||||
"supplier_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control supplier filter reverse indexes caching
|
||||
"attribute_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control attribute filter indexes caching
|
||||
"attribute_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control attribute filter reverse indexes caching
|
||||
"charger_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control charger filter indexes caching
|
||||
"charger_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control charger filter reverse indexes caching
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -149,28 +149,16 @@ func TestCacheJsonCfg(t *testing.T) {
|
||||
Precache: utils.BoolPointer(false)},
|
||||
utils.CacheResourceFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheResourceFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheStatFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheStatFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheThresholdFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheThresholdFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheSupplierFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheSupplierFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheAttributeFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheAttributeFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheChargerFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
utils.CacheChargerFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
|
||||
}
|
||||
|
||||
if gCfg, err := dfCgrJsonCfg.CacheJsonCfg(); err != nil {
|
||||
|
||||
@@ -684,28 +684,16 @@ func TestCgrCfgJSONDefaultsCacheCFG(t *testing.T) {
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheResourceFilterIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheResourceFilterRevIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheStatFilterIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheStatFilterRevIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheThresholdFilterIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheThresholdFilterRevIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheSupplierFilterIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheSupplierFilterRevIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheAttributeFilterIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheAttributeFilterRevIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheChargerFilterIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.CacheChargerFilterRevIndexes: &CacheParamConfig{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(eCacheCfg, cgrCfg.CacheCfg()) {
|
||||
|
||||
@@ -60,15 +60,11 @@
|
||||
"supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"resource_filter_indexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"charger_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -61,15 +61,11 @@
|
||||
"supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"resource_filter_indexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"charger_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -54,15 +54,11 @@
|
||||
"supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"resource_filter_indexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"charger_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -54,15 +54,11 @@
|
||||
"supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"resource_filter_indexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"charger_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -51,15 +51,11 @@
|
||||
"supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"resource_filter_indexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"charger_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -52,15 +52,11 @@
|
||||
"supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true},
|
||||
"resource_filter_indexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"},
|
||||
"charger_filter_indexes" : {"limit": 10000, "ttl":"0s"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -527,7 +527,7 @@ func (dm *DataManager) SetStatQueueProfile(sqp *StatQueueProfile, withIndex bool
|
||||
|
||||
func (dm *DataManager) RemoveStatQueueProfile(tenant, id,
|
||||
transactionID string, withIndex bool) (err error) {
|
||||
oldSts, err := dm.GetResourceProfile(tenant, id, true, utils.NonTransactional)
|
||||
oldSts, err := dm.GetStatQueueProfile(tenant, id, true, utils.NonTransactional)
|
||||
if err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2113,111 +2113,6 @@ func (ms *MongoStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (er
|
||||
return
|
||||
}
|
||||
|
||||
// GetFilterReverseIndexesDrv retrieves ReverseIndexes from dataDB
|
||||
func (ms *MongoStorage) GetFilterReverseIndexesDrv(cacheID, itemIDPrefix string,
|
||||
fldNameVal map[string]string) (revIdx map[string]utils.StringMap, err error) {
|
||||
session, col := ms.conn(colRFI)
|
||||
defer session.Close()
|
||||
dbKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix
|
||||
var result struct {
|
||||
Key string
|
||||
Value map[string][]string
|
||||
}
|
||||
findParam := bson.M{"key": dbKey}
|
||||
if len(fldNameVal) != 0 {
|
||||
for fldName, _ := range fldNameVal {
|
||||
qryFltr := fmt.Sprintf("value.%s", fldName)
|
||||
if err = col.Find(bson.M{"key": dbKey, qryFltr: bson.M{"$exists": true}}).Select(
|
||||
bson.M{qryFltr: true}).One(&result); err != nil {
|
||||
if err == mgo.ErrNotFound {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err = col.Find(findParam).One(&result); err != nil {
|
||||
if err == mgo.ErrNotFound || len(result.Value) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
}
|
||||
}
|
||||
revIdx = make(map[string]utils.StringMap)
|
||||
for key, itmSls := range result.Value {
|
||||
if _, hasIt := revIdx[key]; !hasIt {
|
||||
revIdx[key] = make(utils.StringMap)
|
||||
}
|
||||
revIdx[key] = utils.StringMapFromSlice(itmSls)
|
||||
}
|
||||
if len(revIdx) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return revIdx, nil
|
||||
}
|
||||
|
||||
//SetFilterReverseIndexesDrv stores ReverseIndexes into DataDB
|
||||
func (ms *MongoStorage) SetFilterReverseIndexesDrv(cacheID, itemIDPrefix string,
|
||||
revIdx map[string]utils.StringMap, commit bool, transactionID string) (err error) {
|
||||
session, col := ms.conn(colRFI)
|
||||
defer session.Close()
|
||||
originKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix
|
||||
dbKey := originKey
|
||||
if transactionID != "" {
|
||||
dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID)
|
||||
}
|
||||
if commit && transactionID != "" {
|
||||
oldKey := "tmp_" + utils.ConcatenatedKey(originKey, transactionID)
|
||||
err = col.Remove(bson.M{"key": originKey})
|
||||
if err != nil && err != mgo.ErrNotFound {
|
||||
return
|
||||
}
|
||||
pairs := []interface{}{}
|
||||
for key, itmMp := range revIdx {
|
||||
param := fmt.Sprintf("value.%s", key)
|
||||
pairs = append(pairs, bson.M{"key": originKey})
|
||||
pairs = append(pairs, bson.M{"$set": bson.M{"key": originKey,
|
||||
param: itmMp.Slice()}})
|
||||
}
|
||||
if len(pairs) != 0 {
|
||||
bulk := col.Bulk()
|
||||
bulk.Unordered()
|
||||
bulk.Upsert(pairs...)
|
||||
_, err = bulk.Run()
|
||||
}
|
||||
return col.Remove(bson.M{"key": oldKey})
|
||||
} else {
|
||||
pairs := []interface{}{}
|
||||
for key, itmMp := range revIdx {
|
||||
param := fmt.Sprintf("value.%s", key)
|
||||
pairs = append(pairs, bson.M{"key": dbKey})
|
||||
if len(itmMp) == 0 {
|
||||
pairs = append(pairs, bson.M{"$unset": bson.M{param: 1}})
|
||||
} else {
|
||||
pairs = append(pairs, bson.M{"$set": bson.M{"key": dbKey,
|
||||
param: itmMp.Slice()}})
|
||||
}
|
||||
}
|
||||
if len(pairs) != 0 {
|
||||
bulk := col.Bulk()
|
||||
bulk.Unordered()
|
||||
bulk.Upsert(pairs...)
|
||||
_, err = bulk.Run()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//RemoveFilterReverseIndexesDrv removes ReverseIndexes for a specific itemID
|
||||
func (ms *MongoStorage) RemoveFilterReverseIndexesDrv(cacheID, itemIDPrefix string) (err error) {
|
||||
session, col := ms.conn(colRFI)
|
||||
defer session.Close()
|
||||
err = col.Remove(bson.M{"key": utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix})
|
||||
//redis compatibility
|
||||
if err == mgo.ErrNotFound {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix,
|
||||
filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) {
|
||||
session, col := ms.conn(colRFI)
|
||||
|
||||
@@ -1448,86 +1448,6 @@ func (rs *RedisStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (er
|
||||
return rs.Cmd("DEL", utils.CacheInstanceToPrefix[cacheID]+itemIDPrefix).Err
|
||||
}
|
||||
|
||||
//GetFilterReverseIndexesDrv retrieves ReverseIndexes from dataDB
|
||||
func (rs *RedisStorage) GetFilterReverseIndexesDrv(cacheID, itemIDPrefix string,
|
||||
fldNameVal map[string]string) (indexes map[string]utils.StringMap, err error) {
|
||||
mp := make(map[string]string)
|
||||
dbKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix
|
||||
if len(fldNameVal) == 0 {
|
||||
mp, err = rs.Cmd("HGETALL", dbKey).Map()
|
||||
if err != nil {
|
||||
return
|
||||
} else if len(mp) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
} else {
|
||||
var itmMpStrLst []string
|
||||
for fldName, _ := range fldNameVal {
|
||||
itmMpStrLst, err = rs.Cmd("HMGET", dbKey, fldName).List()
|
||||
if err != nil {
|
||||
return
|
||||
} else if itmMpStrLst[0] == "" {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
mp[fldName] = itmMpStrLst[0]
|
||||
}
|
||||
}
|
||||
indexes = make(map[string]utils.StringMap)
|
||||
for k, v := range mp {
|
||||
var sm utils.StringMap
|
||||
if err = rs.ms.Unmarshal([]byte(v), &sm); err != nil {
|
||||
return
|
||||
}
|
||||
if _, hasKey := indexes[k]; !hasKey {
|
||||
indexes[k] = make(utils.StringMap)
|
||||
}
|
||||
indexes[k] = sm
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//SetFilterReverseIndexesDrv stores ReverseIndexes into DataDB
|
||||
func (rs *RedisStorage) SetFilterReverseIndexesDrv(cacheID, itemIDPrefix string,
|
||||
revIdx map[string]utils.StringMap, commit bool, transactionID string) (err error) {
|
||||
originKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix
|
||||
dbKey := originKey
|
||||
if transactionID != "" {
|
||||
dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID)
|
||||
}
|
||||
if commit && transactionID != "" {
|
||||
return rs.Cmd("RENAME", dbKey, originKey).Err
|
||||
} else {
|
||||
mp := make(map[string]string)
|
||||
nameValSls := []interface{}{dbKey}
|
||||
for key, strMp := range revIdx {
|
||||
if len(strMp) == 0 { // remove with no more elements inside
|
||||
nameValSls = append(nameValSls, key)
|
||||
continue
|
||||
}
|
||||
if encodedMp, err := rs.ms.Marshal(strMp); err != nil {
|
||||
return err
|
||||
} else {
|
||||
mp[key] = string(encodedMp)
|
||||
}
|
||||
}
|
||||
if len(nameValSls) != 1 {
|
||||
if err = rs.Cmd("HDEL", nameValSls...).Err; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(mp) != 0 {
|
||||
return rs.Cmd("HMSET", dbKey, mp).Err
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//RemoveFilterReverseIndexesDrv removes ReverseIndexes for a specific itemID
|
||||
func (rs *RedisStorage) RemoveFilterReverseIndexesDrv(cacheID,
|
||||
itemIDPrefix string) (err error) {
|
||||
return rs.Cmd("DEL", utils.CacheInstanceToPrefix[cacheID]+itemIDPrefix).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix,
|
||||
filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) {
|
||||
fieldValKey := utils.ConcatenatedKey(filterType, fldName, fldVal)
|
||||
|
||||
Reference in New Issue
Block a user