SMGeneric with storeSMCost separately and goroutine only for large timespans

This commit is contained in:
DanB
2016-09-20 18:26:15 +02:00
parent 379f537200
commit 2c8cf6fbc0
3 changed files with 29 additions and 20 deletions

View File

@@ -29,7 +29,6 @@ type CallCost struct {
Direction, Category, Tenant, Subject, Account, Destination, TOR string
Cost float64
Timespans TimeSpans
TimespansMerged bool
RatedUsage float64
deductConnectFee bool
negativeConnectFee bool // the connect fee went negative on default balance

View File

@@ -260,20 +260,14 @@ func (tss *TimeSpans) Decompress() { // must be pointer receiver
func (tss *TimeSpans) Merge() { // Merge whenever possible
tssVal := *tss
if len(tssVal) > 2 {
middle := len(tssVal) / 2
tssVal1 := tssVal[:middle]
tssVal2 := tssVal[middle:]
tssVal1.Merge()
tssVal2.Merge()
tssVal = append(tssVal1, tssVal2 ...)
}
if len(tssVal) > 2 { // Optimization for faster merge
middle := len(tssVal) / 2
tssVal1 := tssVal[:middle]
tssVal2 := tssVal[middle:]
tssVal1.Merge()
tssVal2.Merge()
tssVal = append(tssVal1, tssVal2...)
}
for i := 1; i < len(tssVal); i++ {
if tssVal[i-1].Merge(tssVal[i]) {
tssVal = append(tssVal[:i], tssVal[i+1:]...)