From 3db210ac3901f9ecfeb067a4016775dfbc71c825 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sat, 15 Jun 2024 21:52:15 +0200 Subject: [PATCH] max update 10min and progress returned --- public/elotracker/Tracker.php | 5 ++++- public/elotracker/update.php | 39 ++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/public/elotracker/Tracker.php b/public/elotracker/Tracker.php index c54bcf5..c98675e 100644 --- a/public/elotracker/Tracker.php +++ b/public/elotracker/Tracker.php @@ -98,10 +98,13 @@ class Tracker { return $progressions; } - public function update(): void { + public function update(callable $progressCallback): void { + $counter = 0; foreach ($this->accounts as $puuid => $account) { $account->update($this->entries[$puuid]); + $counter++; + $progressCallback($counter / sizeof($this->accounts)); } } diff --git a/public/elotracker/update.php b/public/elotracker/update.php index 08e3019..2a00299 100644 --- a/public/elotracker/update.php +++ b/public/elotracker/update.php @@ -1,6 +1,43 @@ query(" + SELECT date + FROM updates + WHERE date > SUBTIME(NOW(), '00:10:00') + LIMIT 1 +"); +if ($result->num_rows > 0) { + sendEvent("forbidden", $result->fetch_assoc()["date"]); + die; +} + +$conn->query("INSERT INTO updates VALUES ()"); + require_once __DIR__."/Tracker.php"; +sendEvent("progress", 0); + $tracker = new Tracker(); -$tracker->update(); \ No newline at end of file +$tracker->update(function($value){ + sendEvent('progress', $value); +}); + +sendEvent("done", "");