limit amount of matches used by ranker
This commit is contained in:
parent
67276bd0bb
commit
c30222cf9a
3 changed files with 9 additions and 4 deletions
|
@ -87,9 +87,12 @@ pub struct MatchData {
|
|||
pub match_players: Vec<MatchPlayer>,
|
||||
}
|
||||
|
||||
pub fn list_matches(conn: &PgConnection) -> QueryResult<Vec<FullMatchData>> {
|
||||
pub fn list_matches(amount: i64, conn: &PgConnection) -> QueryResult<Vec<FullMatchData>> {
|
||||
conn.transaction(|| {
|
||||
let matches = matches::table.get_results::<MatchBase>(conn)?;
|
||||
let matches = matches::table
|
||||
.order_by(matches::created_at.desc())
|
||||
.limit(amount)
|
||||
.get_results::<MatchBase>(conn)?;
|
||||
|
||||
let match_players = MatchPlayer::belonging_to(&matches)
|
||||
.left_join(
|
||||
|
|
|
@ -11,7 +11,9 @@ use std::sync::Arc;
|
|||
use std::time::{Duration, Instant};
|
||||
use tokio;
|
||||
|
||||
// TODO: put these in a config
|
||||
const RANKER_INTERVAL: u64 = 60;
|
||||
const RANKER_NUM_MATCHES: i64 = 10_000;
|
||||
|
||||
pub async fn run_ranker(config: Arc<GlobalConfig>, db_pool: DbPool) {
|
||||
// TODO: make this configurable
|
||||
|
@ -80,7 +82,7 @@ struct MatchStats {
|
|||
}
|
||||
|
||||
fn fetch_match_stats(db_conn: &PgConnection) -> QueryResult<HashMap<(i32, i32), MatchStats>> {
|
||||
let matches = db::matches::list_matches(db_conn)?;
|
||||
let matches = db::matches::list_matches(RANKER_NUM_MATCHES, db_conn)?;
|
||||
|
||||
let mut match_stats = HashMap::<(i32, i32), MatchStats>::new();
|
||||
for m in matches {
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct ApiMatchPlayer {
|
|||
}
|
||||
|
||||
pub async fn list_matches(conn: DatabaseConnection) -> Result<Json<Vec<ApiMatch>>, StatusCode> {
|
||||
matches::list_matches(&conn)
|
||||
matches::list_matches(100, &conn)
|
||||
.map_err(|_| StatusCode::BAD_REQUEST)
|
||||
.map(|matches| Json(matches.into_iter().map(match_data_to_api).collect()))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue