fix(speed): Increase query speed
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Matthieu 'JP' DERASSE 2023-06-11 16:15:47 +00:00
parent 699d2721f2
commit 1a013939f5
Signed by: mderasse
GPG Key ID: 55141C777B16A705

View File

@ -12,6 +12,7 @@ import (
) )
var apiClient *api.Client var apiClient *api.Client
var alert = 0
// Init will initialize telegram bot. // Init will initialize telegram bot.
func Init(alertChan chan api.Availability) { 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 // 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 // create a new Ticker
tk := time.NewTicker(interval) tk := time.NewTicker(interval)
resetAlert := 0
for range tk.C { for range tk.C {
if alert > 10 {
alert = 0
resetAlert = 10
continue
}
if resetAlert != 0 {
resetAlert--
continue
}
checkPrice(alertChan) checkPrice(alertChan)
} }
} }
@ -56,5 +69,6 @@ func checkPrice(alertChan chan api.Availability) {
if availabilities.Results[0].Price < PriceAlert { if availabilities.Results[0].Price < PriceAlert {
log.Info("Launching an alert !") log.Info("Launching an alert !")
alertChan <- availabilities.Results[0] alertChan <- availabilities.Results[0]
alert++
} }
} }