From 1a013939f5944c9f502391e314aab3e1bf092897 Mon Sep 17 00:00:00 2001 From: Matthieu 'JP' DERASSE Date: Sun, 11 Jun 2023 16:15:47 +0000 Subject: [PATCH] fix(speed): Increase query speed --- alert/alert.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/alert/alert.go b/alert/alert.go index c2801fb..27e863d 100644 --- a/alert/alert.go +++ b/alert/alert.go @@ -12,6 +12,7 @@ import ( ) var apiClient *api.Client +var alert = 0 // Init will initialize telegram bot. func Init(alertChan chan api.Availability) { @@ -32,11 +33,23 @@ func Init(alertChan chan api.Availability) { } // define an interval and the ticker for this interval - interval := time.Duration(15) * time.Second + interval := time.Duration(5) * time.Second // create a new Ticker tk := time.NewTicker(interval) + resetAlert := 0 for range tk.C { + if alert > 10 { + alert = 0 + resetAlert = 10 + continue + } + + if resetAlert != 0 { + resetAlert-- + continue + } + checkPrice(alertChan) } } @@ -56,5 +69,6 @@ func checkPrice(alertChan chan api.Availability) { if availabilities.Results[0].Price < PriceAlert { log.Info("Launching an alert !") alertChan <- availabilities.Results[0] + alert++ } }