mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 23:58:44 +05:00
Clarify cacheRead and cacheWrite for attributes
This commit is contained in:
committed by
Dan Christian Bogos
parent
0345819718
commit
0dc4c9f363
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user