Skip to content

Commit

Permalink
Remaining stats reads (#9)
Browse files Browse the repository at this point in the history
* Remaining stats reads

* remove format
  • Loading branch information
cmyui authored Apr 21, 2024
1 parent 2bb5df4 commit 627767f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ async fn recalculate_user(
.await?;

let (country, user_privileges): (String, i32) = sqlx::query_as(
"SELECT country, privileges FROM users INNER JOIN users_stats USING(id) WHERE id = ?",
"SELECT country, privileges FROM users WHERE id = ?",
)
.bind(user_id)
.fetch_one(ctx.database.get().await?.deref_mut())
Expand Down
33 changes: 13 additions & 20 deletions src/mass_recalc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn queue_user(user_id: i32, rework: &Rework, context: &Context) -> anyhow:
};

let last_score_time: Option<i32> = sqlx::query_scalar(&format!(
"SELECT max(time) FROM {} INNER JOIN beatmaps USING(beatmap_md5)
WHERE userid = ? AND completed = 3 AND ranked IN (2, 3) AND play_mode = ?
"SELECT max(time) FROM {} INNER JOIN beatmaps USING(beatmap_md5)
WHERE userid = ? AND completed = 3 AND ranked IN (2, 3) AND play_mode = ?
ORDER BY pp DESC LIMIT 100",
scores_table
))
Expand Down Expand Up @@ -127,24 +127,17 @@ pub async fn serve(context: Context) -> anyhow::Result<()> {
.del(format!("rework:leaderboard:{}", rework_id))
.await?;

let stats_prefix = match rework.mode {
0 => "std",
1 => "taiko",
2 => "ctb",
3 => "mania",
_ => unreachable!(),
};

let stats_table = match rework.rx {
0 => "users_stats",
1 => "rx_stats",
2 => "ap_stats",
_ => unreachable!(),
};

let user_ids: Vec<(i32,)> = sqlx::query_as(&format!("SELECT users.id, pp_{} pp FROM {} INNER JOIN users USING(id) WHERE pp_{} > 0 AND users.privileges & 1 ORDER BY pp desc", stats_prefix, stats_table, stats_prefix))
.fetch_all(context.database.get().await?.deref_mut())
.await?;
let user_ids: Vec<(i32,)> = sqlx::query_as(
"SELECT users.id, pp
FROM user_stats
INNER JOIN users ON users.id = user_stats.user_id
WHERE pp > 0 AND mode = ?
AND users.privileges & 1
ORDER BY pp DESC",
)
.bind(rework.mode + (rework.rx * 4))
.fetch_all(context.database.get().await?.deref_mut())
.await?;

for (user_id,) in user_ids {
queue_user(user_id, &rework, &context).await?;
Expand Down

0 comments on commit 627767f

Please sign in to comment.