Adding indexes to postgres tp tables, ApierV1.AddBalance using BalanceId, ApierV1.AddTriggeredAction using ActionTriggersId

This commit is contained in:
DanB
2015-02-20 16:44:08 +01:00
parent 01f1b9aa64
commit 461b715c3b
8 changed files with 37 additions and 22 deletions

View File

@@ -86,7 +86,7 @@ func (self *ApierV1) GetAccount(attr *utils.AttrGetAccount, reply *engine.Accoun
type AttrAddBalance struct {
Tenant string
Account string
BalanceTag string
BalanceId string
BalanceType string
Direction string
Value float64
@@ -134,7 +134,7 @@ func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
BalanceType: attr.BalanceType,
Direction: attr.Direction,
Balance: &engine.Balance{
Id: attr.BalanceTag,
Id: attr.BalanceId,
Value: attr.Value,
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
@@ -413,7 +413,7 @@ func (self *ApierV1) SetActions(attrs AttrSetActions, reply *string) error {
ExtraParameters: apiAct.ExtraParameters,
Balance: &engine.Balance{
Uuid: utils.GenUUID(),
Id: apiAct.BalanceTag,
Id: apiAct.BalanceId,
Value: apiAct.Units,
Weight: apiAct.BalanceWeight,
DestinationId: apiAct.DestinationId,
@@ -534,7 +534,7 @@ func (self *ApierV1) SetActionPlan(attrs AttrSetActionPlan, reply *string) error
}
type AttrAddActionTrigger struct {
Id string
ActionTriggersId string
Tenant string
Account string
ThresholdType string
@@ -560,7 +560,7 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
at := &engine.ActionTrigger{
Id: attr.Id,
Id: attr.ActionTriggersId,
ThresholdType: attr.ThresholdType,
ThresholdValue: attr.ThresholdValue,
BalanceId: attr.BalanceId,

View File

@@ -14,6 +14,7 @@ CREATE TABLE tp_timings (
created_at TIMESTAMP,
UNIQUE (tpid, tag)
);
CREATE INDEX tptimings_idx ON tp_timings (tpid,tag);
--
-- Table structure for table `tp_destinations`
@@ -28,6 +29,7 @@ CREATE TABLE tp_destinations (
created_at TIMESTAMP,
UNIQUE (tpid, tag, prefix)
);
CREATE INDEX tpdests_idx ON tp_destinations (tpid,tag);
--
-- Table structure for table `tp_rates`
@@ -46,6 +48,7 @@ CREATE TABLE tp_rates (
created_at TIMESTAMP,
UNIQUE (tpid, tag, group_interval_start)
);
CREATE INDEX tprates_idx ON tp_rates (tpid,tag);
--
-- Table structure for table `destination_rates`
@@ -63,6 +66,7 @@ CREATE TABLE tp_destination_rates (
created_at TIMESTAMP,
UNIQUE (tpid, tag , destinations_tag)
);
CREATE INDEX tpdestrates_idx ON tp_destination_rates (tpid,tag);
--
-- Table structure for table `tp_rating_plans`
@@ -79,6 +83,8 @@ CREATE TABLE tp_rating_plans (
created_at TIMESTAMP,
UNIQUE (tpid, tag, destrates_tag, timing_tag)
);
CREATE INDEX tpratingplans_idx ON tp_rating_plans (tpid,tag);
--
-- Table structure for table `tp_rate_profiles`
@@ -99,6 +105,7 @@ CREATE TABLE tp_rating_profiles (
created_at TIMESTAMP,
UNIQUE (tpid, loadid, tenant, category, direction, subject, activation_time)
);
CREATE INDEX tpratingprofiles_idx ON tp_rating_profiles (tpid,loadid,direction,tenant,category,subject);
--
-- Table structure for table `tp_shared_groups`
@@ -115,6 +122,7 @@ CREATE TABLE tp_shared_groups (
created_at TIMESTAMP,
UNIQUE (tpid, tag, account , strategy , rating_subject)
);
CREATE INDEX tpsharedgroups_idx ON tp_shared_groups (tpid,tag);
--
-- Table structure for table `tp_actions`
@@ -142,6 +150,7 @@ CREATE TABLE tp_actions (
created_at TIMESTAMP,
UNIQUE (tpid, tag, action, balance_tag, balance_type, direction, expiry_time, timing_tags, destination_tag, shared_group, balance_weight, weight)
);
CREATE INDEX tpactions_idx ON tp_actions (tpid,tag);
--
-- Table structure for table `tp_action_timings`
@@ -158,6 +167,7 @@ CREATE TABLE tp_action_plans (
created_at TIMESTAMP,
UNIQUE (tpid, tag, actions_tag)
);
CREATE INDEX tpactionplans_idx ON tp_action_plans (tpid,tag);
--
-- Table structure for table tp_action_triggers
@@ -189,6 +199,7 @@ CREATE TABLE tp_action_triggers (
created_at TIMESTAMP,
UNIQUE (tpid, tag, balance_tag, balance_type, balance_direction, threshold_type, threshold_value, balance_destination_tag, actions_tag)
);
CREATE INDEX tpactiontrigers_idx ON tp_action_triggers (tpid,tag);
--
-- Table structure for table tp_account_actions
@@ -207,6 +218,7 @@ CREATE TABLE tp_account_actions (
created_at TIMESTAMP,
UNIQUE (tpid, loadid, tenant, account, direction)
);
CREATE INDEX tpaccountactions_idx ON tp_account_actions (tpid,loadid,tenant,account,direction);
--
-- Table structure for table `tp_lcr_rules`
@@ -227,6 +239,7 @@ CREATE TABLE tp_lcr_rules (
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP
);
CREATE INDEX tplcr_idx ON tp_lcr_rules (tpid,direction,tenant,customer,destination_tag);
--
-- Table structure for table `tp_derived_chargers`
@@ -256,6 +269,7 @@ CREATE TABLE tp_derived_chargers (
usage_field VARCHAR(24) NOT NULL,
created_at TIMESTAMP
);
CREATE INDEX tpderivedchargers_idx ON tp_derived_chargers (tpid,loadid,direction,tenant,category,account,subject);
--
@@ -289,3 +303,4 @@ CREATE TABLE tp_cdr_stats (
action_triggers VARCHAR(64) NOT NULL,
created_at TIMESTAMP
);
CREATE INDEX tpcdrstats_idx ON tp_cdr_stats (tpid,tag);

View File

@@ -571,7 +571,7 @@ func (dbr *DbReader) LoadActions() (err error) {
ExpirationString: tpact.ExpiryTime,
Balance: &Balance{
Uuid: utils.GenUUID(),
Id: tpact.BalanceTag,
Id: tpact.BalanceId,
Value: tpact.Units,
Weight: tpact.BalanceWeight,
TimingIDs: tpact.TimingTags,
@@ -660,7 +660,7 @@ func (dbr *DbReader) LoadActionTriggers() (err error) {
ThresholdValue: apiAtr.ThresholdValue,
Recurrent: apiAtr.Recurrent,
MinSleep: apiAtr.MinSleep,
BalanceId: apiAtr.BalanceTag,
BalanceId: apiAtr.BalanceId,
BalanceType: apiAtr.BalanceType,
BalanceDirection: apiAtr.BalanceDirection,
BalanceDestinationId: apiAtr.BalanceDestinationId,
@@ -816,7 +816,7 @@ func (dbr *DbReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions)
atrs[idx] = &ActionTrigger{Id: utils.GenUUID(),
ThresholdType: apiAtr.ThresholdType,
ThresholdValue: apiAtr.ThresholdValue,
BalanceId: apiAtr.BalanceTag,
BalanceId: apiAtr.BalanceId,
BalanceType: apiAtr.BalanceType,
BalanceDirection: apiAtr.BalanceDirection,
BalanceDestinationId: apiAtr.BalanceDestinationId,

View File

@@ -91,7 +91,7 @@ func TestPSQLSetGetTPDestination(t *testing.T) {
}
if dsts, err := psqlDb.GetTpDestinations(TEST_SQL, TEST_SQL); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(dst, dsts[TEST_SQL]) {
} else if len(dst.Prefixes) != len(dsts[TEST_SQL].Prefixes) {
t.Errorf("Expecting: %+v, received: %+v", dst, dsts[TEST_SQL])
}
}
@@ -115,7 +115,7 @@ func TestPSQLSetGetTPRates(t *testing.T) {
}
if rts, err := psqlDb.GetTpRates(TEST_SQL, RT_ID); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(expectedTPRate, rts[RT_ID]) {
} else if len(expectedTPRate.RateSlots) != len(rts[RT_ID].RateSlots) {
for _, slot := range rts[RT_ID].RateSlots {
fmt.Printf("Rates slot receievd: %+v\n", slot)
}

View File

@@ -506,7 +506,7 @@ func (self *SQLStorage) SetTPActions(tpid string, acts map[string][]*utils.TPAct
Tpid: tpid,
Tag: acId,
Action: ac.Identifier,
BalanceTag: ac.BalanceTag,
BalanceTag: ac.BalanceId,
BalanceType: ac.BalanceType,
Direction: ac.Direction,
Units: ac.Units,
@@ -621,7 +621,7 @@ func (self *SQLStorage) SetTPActionTriggers(tpid string, ats map[string][]*utils
ThresholdValue: at.ThresholdValue,
Recurrent: at.Recurrent,
MinSleep: int64(at.MinSleep),
BalanceTag: at.BalanceTag,
BalanceTag: at.BalanceId,
BalanceType: at.BalanceType,
BalanceDirection: at.BalanceDirection,
BalanceDestinationTag: at.BalanceDestinationId,
@@ -1416,7 +1416,7 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*utils.TPAc
for _, tpAc := range tpActions {
a := &utils.TPAction{
Identifier: tpAc.Action,
BalanceTag: tpAc.BalanceTag,
BalanceId: tpAc.BalanceTag,
BalanceType: tpAc.BalanceType,
Direction: tpAc.Direction,
Units: tpAc.Units,
@@ -1448,7 +1448,7 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*uti
ThresholdValue: tpAt.ThresholdValue,
Recurrent: tpAt.Recurrent,
MinSleep: time.Duration(tpAt.MinSleep),
BalanceTag: tpAt.BalanceTag,
BalanceId: tpAt.BalanceTag,
BalanceType: tpAt.BalanceType,
BalanceDirection: tpAt.BalanceDirection,
BalanceDestinationId: tpAt.BalanceDestinationTag,

View File

@@ -403,7 +403,7 @@ func (self *TPCSVImporter) importActions(fn string) error {
}
acts[actId] = append(acts[actId], &utils.TPAction{
Identifier: actionType,
BalanceTag: balanceTag,
BalanceId: balanceTag,
BalanceType: balanceType,
Direction: direction,
Units: units,
@@ -541,7 +541,7 @@ func (self *TPCSVImporter) importActionTriggers(fn string) error {
ThresholdValue: threshold,
Recurrent: recurrent,
MinSleep: minSleep,
BalanceTag: balanceId,
BalanceId: balanceId,
BalanceType: balanceType,
BalanceDirection: direction,
BalanceDestinationId: destinationTag,

View File

@@ -316,7 +316,7 @@ func (self *TPActions) AsExportSlice() [][]string {
type TPAction struct {
Identifier string // Identifier mapped in the code
BalanceTag string // Balance identification string (account scope)
BalanceId string // Balance identification string (account scope)
BalanceType string // Type of balance the action will operate on
Direction string // Balance direction
Units float64 // Number of units to add/deduct
@@ -518,13 +518,13 @@ type TPActionTriggers struct {
ActionTriggers []*TPActionTrigger // Set of triggers grouped in this profile
}
// TPid,Tag[0],ThresholdType[1],ThresholdValue[2],Recurrent[3],MinSleep[4],BalanceTag[5],BalanceType[6],BalanceDirection[7],BalanceCategory[8],BalanceDestinationTag[9],
// TPid,Tag[0],ThresholdType[1],ThresholdValue[2],Recurrent[3],MinSleep[4],BalanceId[5],BalanceType[6],BalanceDirection[7],BalanceCategory[8],BalanceDestinationTag[9],
// BalanceRatingSubject[10],BalanceSharedGroup[11],BalanceExpiryTime[12],BalanceWeight[13],StatsMinQueuedItems[14],ActionsTag[15],Weight[16]
func (self *TPActionTriggers) AsExportSlice() [][]string {
retSlice := make([][]string, len(self.ActionTriggers))
for idx, at := range self.ActionTriggers {
retSlice[idx] = []string{self.ActionTriggersId, at.ThresholdType, strconv.FormatFloat(at.ThresholdValue, 'f', -1, 64), strconv.FormatBool(at.Recurrent), strconv.FormatFloat(at.MinSleep.Seconds(), 'f', -1, 64),
at.BalanceTag, at.BalanceType, at.BalanceDirection, at.BalanceCategory, at.BalanceDestinationId, at.BalanceRatingSubject, at.BalanceSharedGroup, at.BalanceExpirationDate, at.BalanceTimingTags,
at.BalanceId, at.BalanceType, at.BalanceDirection, at.BalanceCategory, at.BalanceDestinationId, at.BalanceRatingSubject, at.BalanceSharedGroup, at.BalanceExpirationDate, at.BalanceTimingTags,
strconv.FormatFloat(at.BalanceWeight, 'f', -1, 64), strconv.Itoa(at.MinQueuedItems), at.ActionsId, strconv.FormatFloat(at.Weight, 'f', -1, 64)}
}
return retSlice
@@ -536,7 +536,7 @@ type TPActionTrigger struct {
ThresholdValue float64 // Threshold
Recurrent bool // reset executed flag each run
MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers
BalanceTag string // The id of the balance in the account
BalanceId string // The id of the balance in the account
BalanceType string // Type of balance this trigger monitors
BalanceDirection string // Traffic direction
BalanceDestinationId string // filter for balance

View File

@@ -416,7 +416,7 @@ func TestTPActionPlanAsExportSlice(t *testing.T) {
ThresholdValue: 2.0,
Recurrent: false,
MinSleep: time.Duration(0),
BalanceTag: "b1",
BalanceId: "b1",
BalanceType: "*monetary",
BalanceDirection: "*out",
BalanceDestinationId: "",
@@ -434,7 +434,7 @@ func TestTPActionPlanAsExportSlice(t *testing.T) {
ThresholdValue: 5.0,
Recurrent: false,
MinSleep: time.Duration(0),
BalanceTag: "b2",
BalanceId: "b2",
BalanceType: "*monetary",
BalanceDirection: "*out",
BalanceDestinationId: "FS_USERS",