From 2122b0f625e04dedba0491c954db231550f07acf Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 23 May 2025 10:51:19 -0500 Subject: [PATCH] Add comments and tweak formatting --- lib/EbookDownloadSummary.php | 2 ++ scripts/recompute-ebook-downloads | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/EbookDownloadSummary.php b/lib/EbookDownloadSummary.php index 951486e6..d7679331 100644 --- a/lib/EbookDownloadSummary.php +++ b/lib/EbookDownloadSummary.php @@ -5,7 +5,9 @@ use Safe\DateTimeImmutable; class EbookDownloadSummary{ public int $EbookId; public DateTimeImmutable $Date; + /** The number of downloads by non-bot clients on the given date. */ public int $DownloadCount = 0; + /** The number of downloads by bot clients on the given date. */ public int $BotDownloadCount = 0; public function __construct(int $ebookId, DateTimeImmutable $date){ diff --git a/scripts/recompute-ebook-downloads b/scripts/recompute-ebook-downloads index d21dcda4..7ad58fef 100755 --- a/scripts/recompute-ebook-downloads +++ b/scripts/recompute-ebook-downloads @@ -35,9 +35,9 @@ foreach($downloadDates as $date){ Db::Query(' UPDATE Ebooks e left join ( - select EbookId, sum(DownloadCount) AS DownloadsPast30Days + select EbookId, sum(DownloadCount) as DownloadsPast30Days from EbookDownloadSummaries - where Date >= curdate() - interval 29 day + where Date >= date(utc_timetamp()) - interval 30 day group by EbookId ) s on e.EbookId = s.EbookId set e.DownloadsPast30Days = coalesce(s.DownloadsPast30Days, 0) @@ -46,7 +46,7 @@ Db::Query(' Db::Query(' UPDATE Ebooks e left join ( - select EbookId, sum(DownloadCount) AS DownloadsTotal + select EbookId, sum(DownloadCount) as DownloadsTotal from EbookDownloadSummaries group by EbookId ) s on e.EbookId = s.EbookId