Skip to content

Commit 9f5a011

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/main' into dependents-search
2 parents c354f91 + e3d6a49 commit 9f5a011

31 files changed

Lines changed: 488 additions & 202 deletions

apps/frontend/wrangler.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"vars": {
5656
"ENVIRONMENT": "staging",
5757
"SENTRY_ENVIRONMENT": "staging",
58-
"BASE_URL": "https://api.modrinth.com/v2/",
59-
"BROWSER_BASE_URL": "https://api.modrinth.com/v2/",
58+
"BASE_URL": "https://staging-api.modrinth.com/v2/",
59+
"BROWSER_BASE_URL": "https://staging-api.modrinth.com/v2/",
6060
"PYRO_BASE_URL": "https://staging-archon.modrinth.com/",
6161
"STRIPE_PUBLISHABLE_KEY": "pk_test_51JbFxJJygY5LJFfKV50mnXzz3YLvBVe2Gd1jn7ljWAkaBlRz3VQdxN9mXcPSrFbSqxwAb0svte9yhnsmm7qHfcWn00R611Ce7b"
6262
},

apps/labrinth/.sqlx/query-654ca85d28573de9b532d0768e5250baa3a5f200fcf9ae990575073d0a1043e0.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-80734c33c16aeacca980cf40070bac035931a0bab8c0d0cf63888c8e5616f847.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

apps/labrinth/.sqlx/query-81b65298ddf4c58b884b15e64f1f4f5aa006944c05980a5b5da366135d17c912.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-e50e308826d1e7fa54cade7daf8120b4ae4068bd086dc08f572b33cfc2476354.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

apps/labrinth/src/clickhouse/mod.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use crate::env::ENV;
99
use crate::queue::server_ping;
1010
use crate::routes::analytics::MINECRAFT_SERVER_PLAYS;
1111

12+
pub const DOWNLOADS: &str = "downloads";
13+
pub const PLAYTIME: &str = "playtime";
14+
1215
pub async fn init_client() -> clickhouse::error::Result<clickhouse::Client> {
1316
init_client_with_database(&ENV.CLICKHOUSE_DATABASE).await
1417
}
@@ -90,7 +93,7 @@ pub async fn init_client_with_database(
9093
client
9194
.query(&format!(
9295
"
93-
CREATE TABLE IF NOT EXISTS {database}.downloads {cluster_line}
96+
CREATE TABLE IF NOT EXISTS {database}.{DOWNLOADS} {cluster_line}
9497
(
9598
recorded DateTime64(4),
9699
domain String,
@@ -117,7 +120,7 @@ pub async fn init_client_with_database(
117120
client
118121
.query(&format!(
119122
"
120-
CREATE TABLE IF NOT EXISTS {database}.playtime {cluster_line}
123+
CREATE TABLE IF NOT EXISTS {database}.{PLAYTIME} {cluster_line}
121124
(
122125
recorded DateTime64(4),
123126
seconds UInt64,
@@ -238,5 +241,27 @@ pub async fn init_client_with_database(
238241
.execute()
239242
.await?;
240243

244+
client
245+
.query(&format!(
246+
"
247+
ALTER TABLE {database}.{DOWNLOADS} {cluster_line}
248+
ADD COLUMN IF NOT EXISTS reason String,
249+
ADD COLUMN IF NOT EXISTS game_version String,
250+
ADD COLUMN IF NOT EXISTS loader String
251+
"
252+
))
253+
.execute()
254+
.await?;
255+
256+
client
257+
.query(&format!(
258+
"
259+
ALTER TABLE {database}.{PLAYTIME} {cluster_line}
260+
ADD COLUMN IF NOT EXISTS country String
261+
"
262+
))
263+
.execute()
264+
.await?;
265+
241266
Ok(client.with_database(database))
242267
}

apps/labrinth/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![recursion_limit = "256"]
2+
13
use std::sync::Arc;
24
use std::time::Duration;
35

apps/labrinth/src/models/v2/search.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ pub struct LegacyResultSearchProject {
1717
pub project_type: String,
1818
pub slug: Option<String>,
1919
pub author: String,
20+
#[serde(default)]
21+
pub author_id: Option<String>,
22+
#[serde(default)]
23+
pub organization: Option<String>,
24+
#[serde(default)]
25+
pub organization_id: Option<String>,
2026
pub title: String,
2127
pub description: String,
2228
pub categories: Vec<String>,
@@ -139,6 +145,9 @@ impl LegacyResultSearchProject {
139145
project_id: result_search_project.project_id,
140146
slug: result_search_project.slug,
141147
author: result_search_project.author,
148+
author_id: result_search_project.author_id,
149+
organization: result_search_project.organization,
150+
organization_id: result_search_project.organization_id,
142151
title: result_search_project.name,
143152
description: result_search_project.summary,
144153
display_categories,

apps/labrinth/src/models/v3/analytics.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ pub struct Download {
2323
pub country: String,
2424
pub user_agent: String,
2525
pub headers: Vec<(String, String)>,
26+
27+
// added retroactively - may be missing
28+
pub reason: Option<DownloadReason>,
29+
pub game_version: Option<String>,
30+
pub loader: Option<String>,
31+
}
32+
33+
/// Why a project was downloaded.
34+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
35+
pub enum DownloadReason {
36+
/// Project was downloaded directly by the user.
37+
Standalone,
38+
/// Project was downloaded as a dependency, possibly transitive, of another
39+
/// project.
40+
Dependency,
41+
/// Project was downloaded as part of a modpack.
42+
Modpack,
2643
}
2744

2845
#[derive(Debug, Row, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
@@ -77,6 +94,9 @@ pub struct Playtime {
7794
pub game_version: String,
7895
/// Parent modpack this playtime was recorded in
7996
pub parent: u64,
97+
98+
// added retroactively - may be missing
99+
pub country: Option<String>,
80100
}
81101

82102
#[derive(Row, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash)]

apps/labrinth/src/routes/analytics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ async fn playtime_ingest(
214214
)
215215
.await?;
216216

217+
let headers = req.headers();
218+
217219
for (id, playtime) in playtimes {
218220
if playtime.seconds > 300 {
219221
continue;
@@ -230,6 +232,9 @@ async fn playtime_ingest(
230232
loader: playtime.loader,
231233
game_version: playtime.game_version,
232234
parent: playtime.parent.map_or(0, |x| x.0),
235+
country: headers
236+
.get("cf-ipcountry")
237+
.and_then(|c| c.to_str().map(|s| s.to_string()).ok()),
233238
});
234239
}
235240
}

0 commit comments

Comments
 (0)