From 149ccc3eacf05ab946d93c062e36d9b19b1b3be6 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 2 Oct 2024 13:06:46 +0200 Subject: [PATCH] Trend.tMux as struct instead of pointer --- engine/libtrends.go | 2 +- engine/libtrends_test.go | 4 ---- engine/trends.go | 4 ---- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/engine/libtrends.go b/engine/libtrends.go index 665a4f788..60c71ea1b 100644 --- a/engine/libtrends.go +++ b/engine/libtrends.go @@ -92,7 +92,7 @@ type TrendWithAPIOpts struct { // Trend is the unit matched by filters type Trend struct { - tMux *sync.RWMutex + tMux sync.RWMutex Tenant string ID string diff --git a/engine/libtrends_test.go b/engine/libtrends_test.go index 645c8a674..cf7238689 100644 --- a/engine/libtrends_test.go +++ b/engine/libtrends_test.go @@ -19,7 +19,6 @@ along with this program. If not, see package engine import ( - "sync" "testing" "time" @@ -32,7 +31,6 @@ func TestTrendGetTrendGrowth(t *testing.T) { t2 := now.Add(-2 * time.Second) t3 := now.Add(-3 * time.Second) trnd1 := &Trend{ - tMux: new(sync.RWMutex), Tenant: "cgrates.org", ID: "TestTrendGetTrendLabel", RunTimes: []time.Time{t3, t2, t1}, @@ -59,8 +57,6 @@ func TestTrendGetTrendLabel(t *testing.T) { t2 := now.Add(-2 * time.Second) t3 := now.Add(-3 * time.Second) trnd1 := &Trend{ - tMux: new(sync.RWMutex), - Tenant: "cgrates.org", ID: "TestTrendGetTrendLabel", RunTimes: []time.Time{t3, t2, t1}, diff --git a/engine/trends.go b/engine/trends.go index da59e20b5..951f9ded4 100644 --- a/engine/trends.go +++ b/engine/trends.go @@ -83,7 +83,6 @@ func (tS *TrendS) computeTrend(tP *TrendProfile) { ID: tP.ID, RunTimes: make([]time.Time, 0), Metrics: make(map[time.Time]map[string]*MetricWithTrend), - tMux: new(sync.RWMutex), } } else if err != nil { utils.Logger.Warning( @@ -92,9 +91,6 @@ func (tS *TrendS) computeTrend(tP *TrendProfile) { utils.TrendS, tP.Tenant, tP.ID, err.Error())) return } - if trend.tMux == nil { - trend.tMux = new(sync.RWMutex) - } trend.tMux.Lock() defer trend.tMux.Unlock() trend.cleanup(tP.TTL, tP.QueueLength)