mirror of
https://github.com/standardebooks/web.git
synced 2025-07-04 13:57:00 -04:00
Change DownloadCount to mean the total number of downloads including bot downloads
This commit is contained in:
parent
2122b0f625
commit
d268681f3c
3 changed files with 8 additions and 7 deletions
|
@ -83,7 +83,9 @@ final class Ebook{
|
|||
/** When the database row was updated. */
|
||||
public DateTimeImmutable $Updated;
|
||||
public ?int $TextSinglePageByteCount = null;
|
||||
/** The numer of non-bot downloads in the past 30 days. */
|
||||
public int $DownloadsPast30Days = 0;
|
||||
/** The numer of all-time non-bot downloads. */
|
||||
public int $DownloadsTotal = 0;
|
||||
|
||||
/** @var array<GitCommit> $_GitCommits */
|
||||
|
|
|
@ -5,7 +5,7 @@ use Safe\DateTimeImmutable;
|
|||
class EbookDownloadSummary{
|
||||
public int $EbookId;
|
||||
public DateTimeImmutable $Date;
|
||||
/** The number of downloads by non-bot clients on the given date. */
|
||||
/** The total number of downloads, including bot downloads, on the given date. */
|
||||
public int $DownloadCount = 0;
|
||||
/** The number of downloads by bot clients on the given date. */
|
||||
public int $BotDownloadCount = 0;
|
||||
|
|
|
@ -19,12 +19,11 @@ foreach($downloadDates as $date){
|
|||
$summaries[$ebookId] = new EbookDownloadSummary($ebookId, $downloadDate);
|
||||
}
|
||||
|
||||
$summaries[$ebookId]->DownloadCount++;
|
||||
|
||||
if($ebookDownload->IsBot()){
|
||||
$summaries[$ebookId]->BotDownloadCount++;
|
||||
}
|
||||
else{
|
||||
$summaries[$ebookId]->DownloadCount++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($summaries as $summary){
|
||||
|
@ -35,9 +34,9 @@ foreach($downloadDates as $date){
|
|||
Db::Query('
|
||||
UPDATE Ebooks e
|
||||
left join (
|
||||
select EbookId, sum(DownloadCount) as DownloadsPast30Days
|
||||
select EbookId, sum(DownloadCount) - sum(BotDownloadCount) as DownloadsPast30Days
|
||||
from EbookDownloadSummaries
|
||||
where Date >= date(utc_timetamp()) - interval 30 day
|
||||
where Date >= date(utc_timestamp()) - interval 30 day
|
||||
group by EbookId
|
||||
) s on e.EbookId = s.EbookId
|
||||
set e.DownloadsPast30Days = coalesce(s.DownloadsPast30Days, 0)
|
||||
|
@ -46,7 +45,7 @@ Db::Query('
|
|||
Db::Query('
|
||||
UPDATE Ebooks e
|
||||
left join (
|
||||
select EbookId, sum(DownloadCount) as DownloadsTotal
|
||||
select EbookId, sum(DownloadCount) - sum(BotDownloadCount) as DownloadsTotal
|
||||
from EbookDownloadSummaries
|
||||
group by EbookId
|
||||
) s on e.EbookId = s.EbookId
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue