From 34bc6107ea7f6cc65c1322c2ede35acde2f57c6e Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 12 Jul 2013 12:23:56 +0300 Subject: [PATCH] use rating profile id for loading from storedb --- apier/apier.go | 10 +++------- docs/apicalls.rst | 7 ++----- rater/ratingprofile.go | 8 ++++---- rater/storage_sql.go | 14 +++++++------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/apier/apier.go b/apier/apier.go index 79da2c372..7d6ab5e12 100644 --- a/apier/apier.go +++ b/apier/apier.go @@ -147,18 +147,14 @@ func (self *Apier) ExecuteAction(attr *AttrExecuteAction, reply *float64) error } type AttrSetRatingProfile struct { - Direction string - Tenant string - TOR string - Subject string - TPID string + TPID string + RateProfileId string } func (self *Apier) SetRatingProfile(attr *AttrSetRatingProfile, reply *float64) error { - tag := fmt.Sprintf("%s:%s:%s:%s", attr.Direction, attr.Tenant, attr.TOR, attr.Subject) dbReader := rater.NewDbReader(self.StorDb, self.DataDb, attr.TPID) - newRP, err := dbReader.LoadRatingProfileByTag(tag) + newRP, err := dbReader.LoadRatingProfileByTag(attr.RateProfileId) if err != nil { return err } diff --git a/docs/apicalls.rst b/docs/apicalls.rst index a238a721e..f9e214dc4 100644 --- a/docs/apicalls.rst +++ b/docs/apicalls.rst @@ -343,11 +343,8 @@ Sets the rating profile for the specified subject. :: type AttrSetRatingProfile struct { - Direction string - Tenant string - TOR string - Subject string - TPID string + TPID string + RatingProfileId string } Example diff --git a/rater/ratingprofile.go b/rater/ratingprofile.go index 2a8205d6b..4e84cc905 100644 --- a/rater/ratingprofile.go +++ b/rater/ratingprofile.go @@ -29,10 +29,10 @@ const ( ) type RatingProfile struct { - Id string - FallbackKey string - DestinationMap map[string][]*ActivationPeriod - ratesTimingTag, activationTime string // used only for loading + Id string + FallbackKey string + DestinationMap map[string][]*ActivationPeriod + tag, ratesTimingTag, activationTime string // used only for loading } // Adds an activation period that applyes to current rating profile if not already present. diff --git a/rater/storage_sql.go b/rater/storage_sql.go index b03bee698..7dc8dcf0a 100644 --- a/rater/storage_sql.go +++ b/rater/storage_sql.go @@ -282,7 +282,7 @@ func (self *SQLStorage) SetTPDestinationRate(dr *utils.TPDestinationRate) error // Using multiple values in query to spare some network processing time qry := fmt.Sprintf("INSERT INTO %s (tpid, tag, destinations_tag, rates_tag) VALUES ", utils.TBL_TP_DESTINATION_RATES) for idx, drPair := range dr.DestinationRates { - if idx!=0 { //Consecutive values after the first will be prefixed with "," as separator + if idx != 0 { //Consecutive values after the first will be prefixed with "," as separator qry += "," } qry += fmt.Sprintf("('%s','%s','%s','%s')", dr.TPid, dr.DestinationRateId, drPair.DestinationId, drPair.RateId) @@ -355,7 +355,7 @@ func (self *SQLStorage) SetTPDestRateTiming(drt *utils.TPDestRateTiming) error { // Using multiple values in query to spare some network processing time qry := fmt.Sprintf("INSERT INTO %s (tpid, tag, destrates_tag, timing_tag, weight) VALUES ", utils.TBL_TP_DESTRATE_TIMINGS) for idx, drtPair := range drt.DestRateTimings { - if idx!=0 { //Consecutive values after the first will be prefixed with "," as separator + if idx != 0 { //Consecutive values after the first will be prefixed with "," as separator qry += "," } qry += fmt.Sprintf("('%s','%s','%s','%s',%f)", drt.TPid, drt.DestRateTimingId, drtPair.DestRatesId, drtPair.TimingId, drtPair.Weight) @@ -382,7 +382,7 @@ func (self *SQLStorage) GetTPDestRateTiming(tpid, drtId string) (*utils.TPDestRa if err != nil { return nil, err } - drt.DestRateTimings = append(drt.DestRateTimings, utils.DestRateTiming{drTag, timingTag,weight}) + drt.DestRateTimings = append(drt.DestRateTimings, utils.DestRateTiming{drTag, timingTag, weight}) } if i == 0 { return nil, nil @@ -682,15 +682,15 @@ func (self *SQLStorage) GetTpRatingProfiles(tpid, tag string) (map[string]*Ratin } for rows.Next() { var id int - var tpid, tenant, tor, direction, subject, fallback_subject, rates_timing_tag, activation_time string + var tpid, tag, tenant, tor, direction, subject, fallback_subject, rates_timing_tag, activation_time string - if err := rows.Scan(&id, &tpid, &tenant, &tor, &direction, &subject, &fallback_subject, &rates_timing_tag, &activation_time); err != nil { + if err := rows.Scan(&id, &tag, &tpid, &tenant, &tor, &direction, &subject, &fallback_subject, &rates_timing_tag, &activation_time); err != nil { return nil, err } key := fmt.Sprintf("%s:%s:%s:%s", direction, tenant, tor, subject) rp, ok := rpfs[key] - if !ok { - rp = &RatingProfile{Id: key} + if !ok || rp.tag != tag { + rp = &RatingProfile{Id: key, tag: tag} rpfs[key] = rp } rp.ratesTimingTag = rates_timing_tag