mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
prevent redundant cost calculations in V1CostForEvent
Previously the function continued looping through all verbosity iterations (default 1000) even after finding a valid cost, causing unnecessary processing.
This commit is contained in:
committed by
Dan Christian Bogos
parent
0937d374e5
commit
07da68b0bb
@@ -128,9 +128,10 @@ func (rS *RateS) V1RateProfileRatesForEvent(ctx *context.Context, args *utils.CG
|
||||
return
|
||||
}
|
||||
|
||||
// V1CostForEvent will be called to calculate the cost for an event
|
||||
//
|
||||
// it will loop through all matching profiles for the event in the eventuality the ones with higher priority are erroring
|
||||
// V1CostForEvent calculates the cost for an event using matching rate
|
||||
// profiles. If a higher priority profile fails, it tries the next matching
|
||||
// profile. This continues until a valid cost is found or all profiles are
|
||||
// exhausted.
|
||||
func (rS *RateS) V1CostForEvent(ctx *context.Context, args *utils.CGREvent, rpCost *utils.RateProfileCost) (err error) {
|
||||
var rPfIDs []string
|
||||
if rPfIDs, err = engine.GetStringSliceOpts(ctx, args.Tenant, args.AsDataProvider(), nil, rS.fltrS, rS.cfg.RateSCfg().Opts.ProfileIDs,
|
||||
@@ -144,7 +145,7 @@ func (rS *RateS) V1CostForEvent(ctx *context.Context, args *utils.CGREvent, rpCo
|
||||
}
|
||||
ignoredRPfIDs := utils.NewStringSet([]string{})
|
||||
var firstError error
|
||||
for i := 0; i < rS.cfg.RateSCfg().Verbosity; i++ {
|
||||
for i := range rS.cfg.RateSCfg().Verbosity {
|
||||
var rtPrl *utils.RateProfile
|
||||
if rtPrl, err = rS.matchingRateProfileForEvent(ctx, args.Tenant, rPfIDs, args, ignFilters, ignoredRPfIDs); err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
@@ -167,6 +168,7 @@ func (rS *RateS) V1CostForEvent(ctx *context.Context, args *utils.CGREvent, rpCo
|
||||
return
|
||||
}
|
||||
*rpCost = *rcvCost
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user