Skip to content

Commit c0d7ef9

Browse files
committed
update_language_countで使用されているsimplify_language内の正規表現のコンパイルが1度だけ実行されるように修正
1 parent 7770125 commit c0d7ef9

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

atcoder-problems-backend/Cargo.lock

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

atcoder-problems-backend/sql-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ anyhow = "1.0"
1616
tokio = { version = "1.16", features = ["macros"] }
1717
regex = "1"
1818
chrono = "0.4"
19+
lazy_static = "1.4.0"

atcoder-problems-backend/sql-client/src/language_count.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::models::{Submission, UserLanguageCount, UserLanguageCountRank, UserPr
22
use crate::{PgPool, MAX_INSERT_ROWS};
33
use anyhow::Result;
44
use async_trait::async_trait;
5+
use lazy_static::lazy_static;
56
use regex::Regex;
67
use sqlx::postgres::PgRow;
78
use sqlx::Row;
@@ -190,11 +191,13 @@ impl LanguageCountClient for PgPool {
190191
}
191192

192193
fn simplify_language(lang: &str) -> String {
193-
let re = Regex::new(r"\d*\s*\(.*\)").unwrap();
194+
lazy_static! {
195+
static ref RE: Regex = Regex::new(r"\d*\s*\(.*\)").unwrap();
196+
}
194197
if lang.starts_with("Perl6") {
195198
"Raku".to_string()
196199
} else {
197-
re.replace(lang, "").to_string()
200+
RE.replace(lang, "").to_string()
198201
}
199202
}
200203

0 commit comments

Comments
 (0)