diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index 23c528641..e845e9f75 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -28,7 +28,7 @@ func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantID, reply *engine.At if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if alsPrf, err := apierV1.DataManager.GetAttributeProfile(arg.Tenant, arg.ID, false, utils.NonTransactional); err != nil { + if alsPrf, err := apierV1.DataManager.GetAttributeProfile(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go index e41c4725b..04b2e698c 100644 --- a/apier/v1/filter_indexes.go +++ b/apier/v1/filter_indexes.go @@ -250,7 +250,7 @@ func (self *ApierV1) ComputeFilterIndexes(args utils.ArgsComputeFilterIndexes, r if attrIndexes != nil { if err := attrIndexes.StoreIndexes(true, transactionID); err != nil { for _, id := range *args.AttributeIDs { - ap, err := self.DataManager.GetAttributeProfile(args.Tenant, id, false, utils.NonTransactional) + ap, err := self.DataManager.GetAttributeProfile(args.Tenant, id, true, false, utils.NonTransactional) if err != nil { return err } @@ -364,7 +364,7 @@ func (self *ApierV1) computeAttributeIndexes(tenant string, attrIDs *[]string, transactionID = utils.NonTransactional } for _, id := range attributeIDs { - ap, err := self.DataManager.GetAttributeProfile(tenant, id, false, utils.NonTransactional) + ap, err := self.DataManager.GetAttributeProfile(tenant, id, true, false, utils.NonTransactional) if err != nil { return nil, err } diff --git a/engine/attributes.go b/engine/attributes.go index c5b827fd5..3d6c78cca 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -85,7 +85,7 @@ func (alS *AttributeService) matchingAttributeProfilesForEvent(args *AttrArgsPro attrIDs = aPrflIDs.Slice() } for _, apID := range attrIDs { - aPrfl, err := alS.dm.GetAttributeProfile(args.Tenant, apID, false, utils.NonTransactional) + aPrfl, err := alS.dm.GetAttributeProfile(args.Tenant, apID, true, true, utils.NonTransactional) if err != nil { if err == utils.ErrNotFound { continue diff --git a/engine/attributes_test.go b/engine/attributes_test.go index f7b571f62..70e11dabf 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -257,7 +257,7 @@ func TestAttributeCache(t *testing.T) { //verify each attribute from cache for _, atr := range atrPs { if tempAttr, err := dmAtr.GetAttributeProfile(atr.Tenant, atr.ID, - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Errorf("Error: %+v", err) } else if !reflect.DeepEqual(atr, tempAttr) { t.Errorf("Expecting: %+v, received: %+v", atr, tempAttr) diff --git a/engine/datamanager.go b/engine/datamanager.go index 808985b51..e7c93e3cf 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -241,7 +241,7 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b _, err = dm.GetSupplierProfile(tntID.Tenant, tntID.ID, true, utils.NonTransactional) case utils.AttributeProfilePrefix: tntID := utils.NewTenantID(dataID) - _, err = dm.GetAttributeProfile(tntID.Tenant, tntID.ID, true, utils.NonTransactional) + _, err = dm.GetAttributeProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional) case utils.ChargerProfilePrefix: tntID := utils.NewTenantID(dataID) _, err = dm.GetChargerProfile(tntID.Tenant, tntID.ID, true, utils.NonTransactional) @@ -1139,10 +1139,10 @@ func (dm *DataManager) RemoveSupplierProfile(tenant, id, transactionID string, w return } -func (dm *DataManager) GetAttributeProfile(tenant, id string, skipCache bool, +func (dm *DataManager) GetAttributeProfile(tenant, id string, cacheRead, cacheWrite bool, transactionID string) (attrPrfl *AttributeProfile, err error) { tntID := utils.ConcatenatedKey(tenant, id) - if !skipCache { + if cacheRead { if x, ok := Cache.Get(utils.CacheAttributeProfiles, tntID); ok { if x == nil { return nil, utils.ErrNotFound @@ -1152,7 +1152,7 @@ func (dm *DataManager) GetAttributeProfile(tenant, id string, skipCache bool, } attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id) if err != nil { - if err == utils.ErrNotFound { + if err == utils.ErrNotFound && cacheWrite { Cache.Set(utils.CacheAttributeProfiles, tntID, nil, nil, cacheCommit(transactionID), transactionID) } @@ -1161,13 +1161,15 @@ func (dm *DataManager) GetAttributeProfile(tenant, id string, skipCache bool, if err = attrPrfl.Compile(); err != nil { return nil, err } - Cache.Set(utils.CacheAttributeProfiles, tntID, attrPrfl, nil, - cacheCommit(transactionID), transactionID) + if cacheWrite { + Cache.Set(utils.CacheAttributeProfiles, tntID, attrPrfl, nil, + cacheCommit(transactionID), transactionID) + } return } func (dm *DataManager) SetAttributeProfile(ap *AttributeProfile, withIndex bool) (err error) { - oldAP, err := dm.GetAttributeProfile(ap.Tenant, ap.ID, false, utils.NonTransactional) + oldAP, err := dm.GetAttributeProfile(ap.Tenant, ap.ID, true, false, utils.NonTransactional) if err != nil && err != utils.ErrNotFound { return err } @@ -1210,7 +1212,7 @@ func (dm *DataManager) SetAttributeProfile(ap *AttributeProfile, withIndex bool) func (dm *DataManager) RemoveAttributeProfile(tenant, id string, contexts []string, transactionID string, withIndex bool) (err error) { - oldAttr, err := dm.GetAttributeProfile(tenant, id, true, utils.NonTransactional) + oldAttr, err := dm.GetAttributeProfile(tenant, id, true, false, utils.NonTransactional) if err != nil && err != utils.ErrNotFound { return err } diff --git a/engine/filterindexer.go b/engine/filterindexer.go index 152435679..6a8a420fe 100644 --- a/engine/filterindexer.go +++ b/engine/filterindexer.go @@ -147,7 +147,7 @@ func (rfi *FilterIndexer) RemoveItemFromIndex(tenant, itemID string, oldFilters } } case utils.AttributeProfilePrefix: - attrPrf, err := rfi.dm.GetAttributeProfile(tenant, itemID, false, utils.NonTransactional) + attrPrf, err := rfi.dm.GetAttributeProfile(tenant, itemID, true, false, utils.NonTransactional) if err != nil && err != utils.ErrNotFound { return err } diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go index 6a9e80395..0981e7c5f 100644 --- a/engine/loader_it_test.go +++ b/engine/loader_it_test.go @@ -486,7 +486,7 @@ func TestLoaderITWriteToDatabase(t *testing.T) { } for tenatid, attrPrf := range loader.attributeProfiles { - rcv, err := loader.dm.GetAttributeProfile(tenatid.Tenant, tenatid.ID, true, utils.NonTransactional) + rcv, err := loader.dm.GetAttributeProfile(tenatid.Tenant, tenatid.ID, false, false, utils.NonTransactional) if err != nil { t.Errorf("Failed GetAttributeProfile, tenant: %s, id: %s, error: %s ", attrPrf.Tenant, attrPrf.ID, err.Error()) } diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index bddb718de..4d165c67b 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -2489,7 +2489,7 @@ func testOnStorITAttributeProfile(t *testing.T) { attributesIdx: mapSubstitutes, } if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { t.Error(rcvErr) } if err := onStor.SetAttributeProfile(attrProfile, false); err != nil { @@ -2497,14 +2497,14 @@ func testOnStorITAttributeProfile(t *testing.T) { } //get from cache if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) } //get from database if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - true, utils.NonTransactional); err != nil { + false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) @@ -2523,14 +2523,14 @@ func testOnStorITAttributeProfile(t *testing.T) { time.Sleep(sleepDelay) //get from cache if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) } //get from database if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - true, utils.NonTransactional); err != nil { + false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) @@ -2541,12 +2541,12 @@ func testOnStorITAttributeProfile(t *testing.T) { } //check cache if removed if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { t.Error(rcvErr) } //check database if removed if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + false, true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { t.Error(rcvErr) } } @@ -2581,7 +2581,7 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { attributesIdx: mapSubstitutes, } if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { + true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { t.Error(rcvErr) } if err := onStor.SetAttributeProfile(attrProfile, false); err != nil { @@ -2589,14 +2589,14 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { } //check cache if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) } //check database if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - true, utils.NonTransactional); err != nil { + false, true, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) @@ -2622,14 +2622,14 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { attrProfile.attributesIdx = mapSubstitutes //check cache if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", utils.ToJSON(attrProfile), utils.ToJSON(rcv)) } //check database if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - true, utils.NonTransactional); err != nil { + false, true, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", utils.ToJSON(attrProfile), utils.ToJSON(rcv)) @@ -2655,14 +2655,14 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { attrProfile.attributesIdx = mapSubstitutes //check cache if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", utils.ToJSON(attrProfile), utils.ToJSON(rcv)) } //check database if rcv, err := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", - true, utils.NonTransactional); err != nil { + false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(attrProfile, rcv)) { t.Errorf("Expecting: %v, received: %v", utils.ToJSON(attrProfile), utils.ToJSON(rcv)) diff --git a/loaders/loader_test.go b/loaders/loader_test.go index 12ca26c52..dcc7f6fd5 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -127,7 +127,7 @@ cgrates.org,TestLoader1,lcr,*string:Account:1008;*string:Account:1009,,Subject,* t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData) } if ap, err := ldr.dm.GetAttributeProfile("cgrates.org", "TestLoader1", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(eAP.Attributes, ap.Attributes) { t.Errorf("expecting: %s, received: %s", @@ -216,7 +216,7 @@ func TestLoaderProcessContentMultiFiles(t *testing.T) { t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData) } if ap, err := ldr.dm.GetAttributeProfile("cgrates.org", "TestLoader2", - false, utils.NonTransactional); err != nil { + true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(eAP.Attributes, ap.Attributes) { t.Errorf("expecting: %s, received: %s", diff --git a/migrator/attributes.go b/migrator/attributes.go index 38f5b9098..beb34ea75 100644 --- a/migrator/attributes.go +++ b/migrator/attributes.go @@ -53,7 +53,7 @@ func (m *Migrator) migrateCurrentAttributeProfile() (err error) { } for _, id := range ids { idg := strings.TrimPrefix(id, utils.AttributeProfilePrefix+tenant+":") - attrPrf, err := m.dmIN.DataManager().GetAttributeProfile(tenant, idg, true, utils.NonTransactional) + attrPrf, err := m.dmIN.DataManager().GetAttributeProfile(tenant, idg, false, false, utils.NonTransactional) if err != nil { return err } diff --git a/migrator/attributes_it_test.go b/migrator/attributes_it_test.go index 7ab9a4e82..d5f391a00 100755 --- a/migrator/attributes_it_test.go +++ b/migrator/attributes_it_test.go @@ -265,7 +265,7 @@ func testAttrITMigrateAndMove(t *testing.T) { t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) } result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", - "ATTR_1", true, utils.NonTransactional) + "ATTR_1", false, false, utils.NonTransactional) if err != nil { t.Error("Error when getting Attribute ", err.Error()) } @@ -285,7 +285,7 @@ func testAttrITMigrateAndMove(t *testing.T) { } _, err = attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", - "ATTR_1", true, utils.NonTransactional) + "ATTR_1", false, false, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) } @@ -295,7 +295,7 @@ func testAttrITMigrateAndMove(t *testing.T) { t.Error("Error when migrating Attributes ", err.Error()) } result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", - "ATTR_1", true, utils.NonTransactional) + "ATTR_1", false, false, utils.NonTransactional) if err != nil { t.Error(err) } @@ -305,7 +305,7 @@ func testAttrITMigrateAndMove(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", attrPrf, result) } result, err = attrMigrator.dmIN.DataManager().GetAttributeProfile("cgrates.org", - "ATTR_1", true, utils.NonTransactional) + "ATTR_1", false, false, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) }