Website: a file downloaded again the same day by the same visitor counts once
15 requests for one APK within a minute from one Windows browser made 18 downloads out of two people. Repeats are now kind 'repeat' (out of the counts, as they were out of the notices); rows from before are marked at start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
63ba4b3e08
commit
b2d440e340
1 changed files with 30 additions and 9 deletions
|
|
@ -211,6 +211,7 @@ async fn main() {
|
|||
)
|
||||
.expect("create the tables");
|
||||
migrate(&db);
|
||||
mark_repeats(&db);
|
||||
let geoip: Vec<_> = config
|
||||
.geoip_paths
|
||||
.iter()
|
||||
|
|
@ -345,6 +346,22 @@ fn migrate(db: &rusqlite::Connection) {
|
|||
}
|
||||
}
|
||||
|
||||
/// A file downloaded again the same day by the same visitor (a download manager or
|
||||
/// browser asking again, a button pressed twice) is one download: the later rows are
|
||||
/// `repeat`, out of the counts, as they are out of the notices. Runs at every start, for
|
||||
/// the rows from before this rule (15 requests for one APK in a minute, 2026-10-29).
|
||||
fn mark_repeats(db: &rusqlite::Connection) {
|
||||
if let Err(e) = db.execute(
|
||||
"UPDATE downloads SET kind = 'repeat'
|
||||
WHERE kind = 'human' AND visitor IS NOT NULL AND id NOT IN (
|
||||
SELECT MIN(id) FROM downloads WHERE kind = 'human' AND visitor IS NOT NULL
|
||||
GROUP BY visitor, platform, date(ts, 'localtime'))",
|
||||
[],
|
||||
) {
|
||||
eprintln!("marking repeated downloads failed: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
/// What is known about the visitor of a request.
|
||||
struct Client {
|
||||
country: Option<String>,
|
||||
|
|
@ -845,6 +862,18 @@ async fn download(
|
|||
);
|
||||
}
|
||||
}
|
||||
// The same file again today from the same visitor: counted once (see `mark_repeats`).
|
||||
let again: bool = db
|
||||
.query_row(
|
||||
"SELECT COUNT(*) > 0 FROM downloads WHERE visitor = ?1 AND platform = ?2
|
||||
AND date(ts, 'localtime') = date('now', 'localtime')",
|
||||
rusqlite::params![c.visitor, asset.platform],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap_or(false);
|
||||
if kind == "human" && again {
|
||||
kind = "repeat";
|
||||
}
|
||||
let _ = db.execute(
|
||||
"INSERT INTO downloads (ts, platform, version, asset, country, region, city, lang, referrer, visitor, kind, ua)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)",
|
||||
|
|
@ -865,15 +894,7 @@ async fn download(
|
|||
);
|
||||
// People only: not crawlers, not the owner, not the local network; one notice a
|
||||
// day per file and visitor (a download started again is not another person).
|
||||
let again: bool = db
|
||||
.query_row(
|
||||
"SELECT COUNT(*) > 1 FROM downloads WHERE visitor = ?1 AND platform = ?2
|
||||
AND date(ts, 'localtime') = date('now', 'localtime')",
|
||||
rusqlite::params![c.visitor, asset.platform],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap_or(false);
|
||||
if kind == "human" && asset.platform != "checksums" && !again {
|
||||
if kind == "human" && asset.platform != "checksums" {
|
||||
let place =
|
||||
telegram::place(c.country.as_deref(), c.region.as_deref(), c.city.as_deref());
|
||||
let from = referrer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue