From 358c5bcbd7c8f2b8625cc6edab4d16c407e6d7d1 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 5 Oct 2025 10:04:27 +0200 Subject: [PATCH] chore: prevent copying rates --- tariff/proxy.go | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/tariff/proxy.go b/tariff/proxy.go index 3b470a464..c466bc8f2 100644 --- a/tariff/proxy.go +++ b/tariff/proxy.go @@ -164,16 +164,7 @@ func (p *CachingProxy) cacheGet(until time.Time) (*cached, error) { return nil, errors.New("not enough rates") } - res := &cached{ - Rates: currentRates(p.cached.Rates), - Type: p.cached.Type, - } - - if len(res.Rates) == 0 { - return nil, errors.New("no current rates") - } - - return res, nil + return p.cached, nil } func (p *CachingProxy) cachePut(typ api.TariffType, rates api.Rates) error { @@ -197,16 +188,3 @@ func untilEndOfTomorrow() time.Time { func ratesValid(rr api.Rates, until time.Time) bool { return len(rr) > 0 && !rr[len(rr)-1].End.Before(until) } - -func currentRates(rr api.Rates) api.Rates { - res := make(api.Rates, 0, len(rr)) - now := time.Now().Truncate(SlotDuration) - - for _, r := range rr { - if r.End.After(now) { - res = append(res, r) - } - } - - return res -}