mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add GetLCR in DataManager
This commit is contained in:
committed by
Dan Christian Bogos
parent
21f21f4b03
commit
aa00c1aaba
@@ -958,7 +958,7 @@ func (cd *CallDescriptor) GetLCRFromStorage() (*LCR, error) {
|
||||
keyVariants = append(keyVariants[:1], append(partialSubjects, keyVariants[1:]...)...)
|
||||
}
|
||||
for _, key := range keyVariants {
|
||||
if lcr, err := dm.DataDB().GetLCR(key, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
|
||||
if lcr, err := dm.GetLCR(key, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
|
||||
return nil, err
|
||||
} else if err == nil && lcr != nil {
|
||||
return lcr, nil
|
||||
|
||||
@@ -181,7 +181,7 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
|
||||
case utils.DERIVEDCHARGERS_PREFIX:
|
||||
_, err = dm.DataDB().GetDerivedChargers(dataID, true, utils.NonTransactional)
|
||||
case utils.LCR_PREFIX:
|
||||
_, err = dm.DataDB().GetLCR(dataID, true, utils.NonTransactional)
|
||||
_, err = dm.GetLCR(dataID, true, utils.NonTransactional)
|
||||
case utils.ALIASES_PREFIX:
|
||||
_, err = dm.DataDB().GetAlias(dataID, true, utils.NonTransactional)
|
||||
case utils.REVERSE_ALIASES_PREFIX:
|
||||
@@ -523,3 +523,24 @@ func (dm *DataManager) RemoveActionTriggers(id, transactionID string) (err error
|
||||
cache.RemKey(utils.ACTION_TRIGGER_PREFIX+id, cacheCommit(transactionID), transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
func (dm *DataManager) GetLCR(id string, skipCache bool, transactionID string) (lcr *LCR, err error) {
|
||||
key := utils.LCR_PREFIX + id
|
||||
if !skipCache {
|
||||
if x, ok := cache.Get(key); ok {
|
||||
if x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return x.(*LCR), nil
|
||||
}
|
||||
}
|
||||
lcr, err = dm.DataDB().GetLCRDrv(id)
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
cache.Set(key, nil, cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
cache.Set(key, lcr, cacheCommit(transactionID), transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ func TestLoaderITWriteToDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
for k, lcr := range loader.lcrs {
|
||||
rcv, err := loader.dataStorage.GetLCR(k, true, utils.NonTransactional)
|
||||
rcv, err := loader.dm.GetLCR(k, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Failed GetLCR: ", err.Error())
|
||||
}
|
||||
|
||||
@@ -1218,13 +1218,13 @@ func testOnStorITCRUDLCR(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if _, rcvErr := onStor.DataDB().GetLCR(lcr.GetId(), true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetLCR(lcr.GetId(), true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.DataDB().SetLCR(lcr, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.DataDB().GetLCR(lcr.GetId(), true, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetLCR(lcr.GetId(), true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(lcr, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", lcr, rcv)
|
||||
@@ -1237,7 +1237,7 @@ func testOnStorITCRUDLCR(t *testing.T) {
|
||||
// t.Error(rcvErr)
|
||||
// }
|
||||
//
|
||||
if rcv, err := onStor.DataDB().GetLCR(lcr.GetId(), false, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetLCR(lcr.GetId(), false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(lcr, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", lcr, rcv)
|
||||
|
||||
@@ -59,7 +59,7 @@ type DataDB interface {
|
||||
SetReverseDestination(*Destination, string) error
|
||||
GetReverseDestination(string, bool, string) ([]string, error)
|
||||
UpdateReverseDestination(*Destination, *Destination, string) error
|
||||
GetLCR(string, bool, string) (*LCR, error)
|
||||
GetLCRDrv(string) (*LCR, error)
|
||||
SetLCR(*LCR, string) error
|
||||
SetCdrStats(*CdrStats) error
|
||||
GetCdrStats(string) (*CdrStats, error)
|
||||
|
||||
@@ -285,26 +285,15 @@ func (ms *MapStorage) RemoveRatingProfile(key string, transactionID string) (err
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetLCR(key string, skipCache bool, transactionID string) (lcr *LCR, err error) {
|
||||
func (ms *MapStorage) GetLCRDrv(id string) (lcr *LCR, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
key = utils.LCR_PREFIX + key
|
||||
if !skipCache {
|
||||
if x, ok := cache.Get(key); ok {
|
||||
if x != nil {
|
||||
return x.(*LCR), nil
|
||||
}
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
}
|
||||
cCommit := cacheCommit(transactionID)
|
||||
key := utils.LCR_PREFIX + id
|
||||
if values, ok := ms.dict[key]; ok {
|
||||
err = ms.ms.Unmarshal(values, &lcr)
|
||||
} else {
|
||||
cache.Set(key, nil, cCommit, transactionID)
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
cache.Set(key, lcr, cCommit, transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -735,32 +735,21 @@ func (ms *MongoStorage) RemoveRatingProfile(key, transactionID string) error {
|
||||
return iter.Close()
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetLCR(key string, skipCache bool, transactionID string) (lcr *LCR, err error) {
|
||||
cacheKey := utils.LCR_PREFIX + key
|
||||
if !skipCache {
|
||||
if x, ok := cache.Get(cacheKey); ok {
|
||||
if x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return x.(*LCR), nil
|
||||
}
|
||||
}
|
||||
func (ms *MongoStorage) GetLCRDrv(key string) (lcr *LCR, err error) {
|
||||
|
||||
var result struct {
|
||||
Key string
|
||||
Value *LCR
|
||||
}
|
||||
session, col := ms.conn(colLcr)
|
||||
defer session.Close()
|
||||
cCommit := cacheCommit(transactionID)
|
||||
if err = col.Find(bson.M{"key": key}).One(&result); err != nil {
|
||||
if err == mgo.ErrNotFound {
|
||||
cache.Set(cacheKey, nil, cCommit, transactionID)
|
||||
err = utils.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
lcr = result.Value
|
||||
cache.Set(cacheKey, lcr, cCommit, transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -326,20 +326,11 @@ func (rs *RedisStorage) RemoveRatingProfile(key string, transactionID string) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetLCR(key string, skipCache bool, transactionID string) (lcr *LCR, err error) {
|
||||
key = utils.LCR_PREFIX + key
|
||||
if !skipCache {
|
||||
if x, ok := cache.Get(key); ok {
|
||||
if x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return x.(*LCR), nil
|
||||
}
|
||||
}
|
||||
func (rs *RedisStorage) GetLCRDrv(id string) (lcr *LCR, err error) {
|
||||
key := utils.LCR_PREFIX + id
|
||||
var values []byte
|
||||
if values, err = rs.Cmd("GET", key).Bytes(); err != nil {
|
||||
if err == redis.ErrRespNil { // did not find the destination
|
||||
cache.Set(key, nil, cacheCommit(transactionID), transactionID)
|
||||
err = utils.ErrNotFound
|
||||
}
|
||||
return
|
||||
@@ -347,7 +338,6 @@ func (rs *RedisStorage) GetLCR(key string, skipCache bool, transactionID string)
|
||||
if err = rs.ms.Unmarshal(values, &lcr); err != nil {
|
||||
return
|
||||
}
|
||||
cache.Set(key, lcr, cacheCommit(transactionID), transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user