From 2bcd034c02996b20843ab31fbf9db95632021af1 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Mon, 7 Feb 2022 16:43:20 +0200 Subject: [PATCH] Added copunt/list rates for internal driver --- engine/datadbmock.go | 6 +++--- engine/datamanager.go | 8 +++----- engine/storage_interface.go | 2 +- engine/storage_internal_datadb.go | 11 ++++++++++- engine/storage_mongo_datadb.go | 2 +- engine/storage_redis.go | 7 ++++++- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/engine/datadbmock.go b/engine/datadbmock.go index e13d51677..7a74513cd 100644 --- a/engine/datadbmock.go +++ b/engine/datadbmock.go @@ -27,7 +27,7 @@ type DataDBMock struct { RemoveRateProfileDrvF func(ctx *context.Context, str1 string, str2 string, rateIDs *[]string) error SetRateProfileDrvF func(*context.Context, *utils.RateProfile) error GetRateProfileDrvF func(*context.Context, string, string) (*utils.RateProfile, error) - GetRateProfileRateidSDrvF func(*context.Context, string, string) ([]string, error) + GetRateProfileRateidSDrvF func(*context.Context, string, string, string) ([]string, error) GetKeysForPrefixF func(*context.Context, string) ([]string, error) GetIndexesDrvF func(ctx *context.Context, idxItmType, tntCtx, idxKey, transactionID string) (indexes map[string]utils.StringSet, err error) SetIndexesDrvF func(ctx *context.Context, idxItmType, tntCtx string, indexes map[string]utils.StringSet, commit bool, transactionID string) (err error) @@ -376,9 +376,9 @@ func (dbM *DataDBMock) GetRateProfileDrv(ctx *context.Context, tnt string, id st return nil, utils.ErrNotImplemented } -func (dbM *DataDBMock) GetRateProfileRateIDsDrv(ctx *context.Context, tnt string, id string) ([]string, error) { +func (dbM *DataDBMock) GetRateProfileRateIDsDrv(ctx *context.Context, tnt string, id string, prefixArgs string) ([]string, error) { if dbM.GetRateProfileRateidSDrvF != nil { - return dbM.GetRateProfileRateIDsDrv(ctx, tnt, id) + return dbM.GetRateProfileRateIDsDrv(ctx, tnt, id, prefixArgs) } return nil, utils.ErrNotImplemented } diff --git a/engine/datamanager.go b/engine/datamanager.go index 8ca988af4..82ebbf623 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -1944,12 +1944,10 @@ func (dm *DataManager) GetRateProfile(ctx *context.Context, tenant, id string, c } func (dm *DataManager) GetRateProfileRateIDs(ctx *context.Context, args *utils.ArgsSubItemIDs) (rateIDs []string, err error) { - key := utils.RateProfilePrefix + utils.ConcatenatedKey(args.Tenant, args.ProfileID) - prefix := utils.Rates + utils.ConcatenatedKeySep - if args.ItemsPrefix != utils.EmptyString { - prefix = utils.ConcatenatedKey(utils.Rates, args.ItemsPrefix) + if dm == nil { + return nil, utils.ErrNoDatabaseConn } - return dm.DataDB().GetRateProfileRateIDsDrv(ctx, key, prefix) + return dm.DataDB().GetRateProfileRateIDsDrv(ctx, args.Tenant, args.ProfileID, args.ItemsPrefix) } func (dm *DataManager) SetRateProfile(ctx *context.Context, rpp *utils.RateProfile, withIndex bool) (err error) { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index d43b6b7ff..f9c0c935f 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -86,7 +86,7 @@ type DataDB interface { SetDispatcherHostDrv(*context.Context, *DispatcherHost) error RemoveDispatcherHostDrv(*context.Context, string, string) error GetRateProfileDrv(*context.Context, string, string) (*utils.RateProfile, error) - GetRateProfileRateIDsDrv(*context.Context, string, string) ([]string, error) + GetRateProfileRateIDsDrv(*context.Context, string, string, string) ([]string, error) SetRateProfileDrv(*context.Context, *utils.RateProfile) error RemoveRateProfileDrv(*context.Context, string, string, *[]string) error GetActionProfileDrv(*context.Context, string, string) (*ActionProfile, error) diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index d8f688e9d..6ed4d9ab2 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -476,7 +476,16 @@ func (iDB *InternalDB) GetRateProfileDrv(_ *context.Context, tenant, id string) return x.(*utils.RateProfile), nil } -func (iDB *InternalDB) GetRateProfileRateIDsDrv(ctx *context.Context, key, prefix string) (rateIDs []string, err error) { +func (iDB *InternalDB) GetRateProfileRateIDsDrv(ctx *context.Context, tenant, profileID, prefixArgs string) (rateIDs []string, err error) { + x, ok := iDB.db.Get(utils.CacheRateProfiles, utils.ConcatenatedKey(tenant, profileID)) + if !ok || x == nil { + return nil, utils.ErrNotFound + } + for key := range x.(*utils.RateProfile).Rates { + if strings.HasPrefix(key, prefixArgs) { + rateIDs = append(rateIDs, key) + } + } return } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 4eb81dfaf..3ac465357 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1221,7 +1221,7 @@ func (ms *MongoStorage) GetRateProfileDrv(ctx *context.Context, tenant, id strin return utils.NewRateProfileFromMapDataDBMap(tenant, id, mapRP, ms.ms) } -func (ms *MongoStorage) GetRateProfileRateIDsDrv(ctx *context.Context, key, prefix string) (rateIDs []string, err error) { +func (ms *MongoStorage) GetRateProfileRateIDsDrv(ctx *context.Context, key, prefix, argsPrefix string) (rateIDs []string, err error) { return } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 691d14f4e..8057f125f 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -748,7 +748,12 @@ func (rs *RedisStorage) GetRateProfileDrv(ctx *context.Context, tenant, id strin return utils.NewRateProfileFromMapDataDBMap(tenant, id, mapRP, rs.ms) } -func (rs *RedisStorage) GetRateProfileRateIDsDrv(ctx *context.Context, key, prefix string) (rateIDs []string, err error) { +func (rs *RedisStorage) GetRateProfileRateIDsDrv(ctx *context.Context, tnt, profileID, prefixArgs string) (rateIDs []string, err error) { + key := utils.RateProfilePrefix + utils.ConcatenatedKey(tnt, profileID) + prefix := utils.Rates + utils.ConcatenatedKeySep + if prefixArgs != utils.EmptyString { + prefix = utils.ConcatenatedKey(utils.Rates, prefixArgs) + } var rateField string scan := radix.NewScanner(rs.client, radix.ScanOpts{ Command: redisHSCAN,