[CacheS] CacheDataFromDB only if limit for items is different than 0

This commit is contained in:
TeoV
2020-05-11 17:24:32 +03:00
committed by Dan Christian Bogos
parent 0a58f1886f
commit 3461db493d
7 changed files with 26 additions and 2 deletions

View File

@@ -100,7 +100,6 @@ func (dbcfg *DataDbCfg) loadFromJsonCfg(jsnDbCfg *DbJsonCfg) (err error) {
}
}
if jsnDbCfg.Items != nil {
dbcfg.Items = make(map[string]*ItemOpt)
for kJsn, vJsn := range *jsnDbCfg.Items {
val, has := dbcfg.Items[kJsn]
if val == nil || !has {

View File

@@ -398,6 +398,7 @@ func TestDataDbCfgloadFromJsonCfgItems(t *testing.T) {
func TestDataDbCfgAsMapInterface(t *testing.T) {
var dbcfg DataDbCfg
dbcfg.Items = make(map[string]*ItemOpt)
cfgJSONStr := `{
"data_db": {
"db_type": "*redis",

View File

@@ -197,6 +197,9 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
utils.UnsupportedCachePrefix,
fmt.Sprintf("prefix <%s> is not a supported cache prefix", prfx))
}
if dm.cacheCfg[utils.CachePrefixToInstance[prfx]].Limit == 0 {
return
}
if ids == nil {
keyIDs, err := dm.DataDB().GetKeysForPrefix(prfx)
if err != nil {

View File

@@ -92,7 +92,7 @@ func testLoaderITInitDataDB(t *testing.T) {
if err != nil {
t.Fatal("Error on dataDb connection: ", err.Error())
}
dataDbCsv = NewDataManager(dbConn, nil, nil)
dataDbCsv = NewDataManager(dbConn, lCfg.CacheCfg(), nil)
if err = dbConn.Flush(utils.EmptyString); err != nil {
t.Fatal("Error when flushing datadb")
}

View File

@@ -143,6 +143,9 @@ func testOnStorITIsDBEmpty(t *testing.T) {
}
func testOnStorITCacheDestinations(t *testing.T) {
if onStor.dataDB.GetStorageType() == utils.INTERNAL {
t.SkipNow()
}
if err := onStor.CacheDataFromDB("INVALID", nil, false); err == nil || err.Error() != utils.UnsupportedCachePrefix {
t.Error(err)
}
@@ -163,6 +166,7 @@ func testOnStorITCacheDestinations(t *testing.T) {
if err := onStor.CacheDataFromDB(utils.DESTINATION_PREFIX, []string{dst.Id}, false); err != nil {
t.Error(err)
}
if itm, hasIt := Cache.Get(utils.CacheDestinations, dst.Id); !hasIt {
t.Error("Did not cache")
} else if !reflect.DeepEqual(dst, itm.(*Destination)) {
@@ -171,6 +175,9 @@ func testOnStorITCacheDestinations(t *testing.T) {
}
func testOnStorITCacheReverseDestinations(t *testing.T) {
if onStor.dataDB.GetStorageType() == utils.INTERNAL {
t.SkipNow()
}
dst := &Destination{Id: "TEST_CACHE", Prefixes: []string{"+491", "+492", "+493"}}
if err := onStor.SetReverseDestination(dst, utils.NonTransactional); err != nil {
t.Error(err)
@@ -193,6 +200,9 @@ func testOnStorITCacheReverseDestinations(t *testing.T) {
}
func testOnStorITCacheActionPlan(t *testing.T) {
if onStor.dataDB.GetStorageType() == utils.INTERNAL {
t.SkipNow()
}
ap := &ActionPlan{
Id: "MORE_MINUTES",
AccountIDs: utils.StringMap{"vdf:minitsboy": true},
@@ -256,6 +266,9 @@ func testOnStorITCacheActionPlan(t *testing.T) {
}
func testOnStorITCacheAccountActionPlans(t *testing.T) {
if onStor.dataDB.GetStorageType() == utils.INTERNAL {
t.SkipNow()
}
acntID := utils.ConcatenatedKey("cgrates.org", "1001")
aAPs := []string{"PACKAGE_10_SHARED_A_5", "USE_SHARED_A", "apl_PACKAGE_1001"}
if err := onStor.SetAccountActionPlans(acntID, aAPs, true); err != nil {

View File

@@ -324,6 +324,9 @@ func TestResourceAllocateResource(t *testing.T) {
// TestRSCacheSetGet assurace the presence of private params in cached resource
func TestRSCacheSetGet(t *testing.T) {
if *dbType == utils.MetaInternal {
t.SkipNow()
}
r := &Resource{
Tenant: "cgrates.org",
ID: "RL",
@@ -719,6 +722,9 @@ func TestResourceIDs(t *testing.T) {
}
func TestResourceCaching(t *testing.T) {
if *dbType == utils.MetaInternal {
t.SkipNow()
}
//clear the cache
Cache.Clear(nil)
// start fresh with new dataManager

View File

@@ -24,6 +24,8 @@ cgrates (0.10.1~dev) UNRELEASED; urgency=medium
* [AgentRequest] Improved NavigableMap
* [AgentRequest] FieldAsInterface return Data instead of NMItem
* [SupplierS] Allow multiple suppliers with the same ID
* [Engine] Skip caching is limit is 0
* [CacheS] Avoid long recaching
-- Alexandru Tripon <alexandru.tripon@itsyscom.com> Wed, 19 Feb 2020 15:22:59 +0200