Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix views analytics (#885)
Browse files Browse the repository at this point in the history
* fix views analytics

* update ip stripping

* update clickhouse tables

* fix broken queries

* Fix panics

* fix download undercounting

* fix packerator failing sometimes

* run prep
  • Loading branch information
Geometrically authored Mar 2, 2024
1 parent 04d8341 commit e2ffeab
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 140 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/clickhouse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ pub async fn init_client_with_database(
user_id UInt64,
project_id UInt64,
monetized Bool DEFAULT True,
ip IPv6,
country String,
user_agent String,
headers Array(Tuple(String, String)),
headers Array(Tuple(String, String))
)
ENGINE = MergeTree()
PRIMARY KEY (project_id, recorded)
PRIMARY KEY (project_id, recorded, ip)
"
))
.execute()
Expand All @@ -71,10 +72,10 @@ pub async fn init_client_with_database(
ip IPv6,
country String,
user_agent String,
headers Array(Tuple(String, String)),
headers Array(Tuple(String, String))
)
ENGINE = MergeTree()
PRIMARY KEY (project_id, recorded)
PRIMARY KEY (project_id, recorded, ip)
"
))
.execute()
Expand All @@ -94,10 +95,10 @@ pub async fn init_client_with_database(
loader String,
game_version String,
parent UInt64,
parent UInt64
)
ENGINE = MergeTree()
PRIMARY KEY (project_id, recorded)
PRIMARY KEY (project_id, recorded, user_id)
"
))
.execute()
Expand Down
40 changes: 20 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use util::cors::default_cors;

use crate::queue::moderation::AutomatedModerationQueue;
use crate::{
// queue::payouts::process_payout,
queue::payouts::process_payout,
search::indexing::index_projects,
util::env::{parse_strings_from_var, parse_var},
};
Expand Down Expand Up @@ -214,25 +214,25 @@ pub fn app_setup(
});
}

// {
// let pool_ref = pool.clone();
// let redis_ref = redis_pool.clone();
// let client_ref = clickhouse.clone();
// scheduler.run(std::time::Duration::from_secs(60 * 60 * 6), move || {
// let pool_ref = pool_ref.clone();
// let redis_ref = redis_ref.clone();
// let client_ref = client_ref.clone();
//
// async move {
// info!("Started running payouts");
// let result = process_payout(&pool_ref, &redis_ref, &client_ref).await;
// if let Err(e) = result {
// warn!("Payouts run failed: {:?}", e);
// }
// info!("Done running payouts");
// }
// });
// }
{
let pool_ref = pool.clone();
let redis_ref = redis_pool.clone();
let client_ref = clickhouse.clone();
scheduler.run(std::time::Duration::from_secs(60 * 60 * 6), move || {
let pool_ref = pool_ref.clone();
let redis_ref = redis_ref.clone();
let client_ref = client_ref.clone();

async move {
info!("Started running payouts");
let result = process_payout(&pool_ref, &redis_ref, &client_ref).await;
if let Err(e) = result {
warn!("Payouts run failed: {:?}", e);
}
info!("Done running payouts");
}
});
}

let ip_salt = Pepper {
pepper: models::ids::Base62Id(models::ids::random_base62(11)).to_string(),
Expand Down
2 changes: 2 additions & 0 deletions src/models/v3/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct PageView {
pub user_id: u64,
// Modrinth Project ID (used for payouts)
pub project_id: u64,
// whether this view will be monetized / counted for payouts
pub monetized: bool,

// The below information is used exclusively for data aggregation and fraud detection
// (ex: page view botting).
Expand Down
Loading

0 comments on commit e2ffeab

Please sign in to comment.