Skip to content

[replacement with sqlx] LanguageCountClient #770

Merged
kenkoooo merged 6 commits intokenkoooo:masterfrom
magurotuna:language-count-client-sqlx
Aug 22, 2020
Merged

[replacement with sqlx] LanguageCountClient #770
kenkoooo merged 6 commits intokenkoooo:masterfrom
magurotuna:language-count-client-sqlx

Conversation

@magurotuna
Copy link
Copy Markdown
Contributor

@magurotuna magurotuna commented Aug 17, 2020

Related issue: #701

LanguageCountClient の sqlx 版です。

やったこと

  • 非同期対応の LanguageCountClient を作って、それを sqlx::postgres::PgPool に対して実装
  • LanguageCountClient のテストを作成(もとのテストを移植)
  • std::iter::Iterator::unzip をn要素に拡張する unzip_nを使ってリファクタリング

#[async_trait]
impl LanguageCountClient for PgPool {
async fn update_language_count(&self, submissions: &[Submission]) -> Result<()> {
let re = Regex::new(r"\d* \(.*\)").unwrap();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは古いやつから残っているのですが、AtCoder 側の入力ミス?で Fortran(GNU Fortran 9.2.1) という書式のものが登場して、これをパースできないので、カッコの前のスペースを消して \d*\(.*\) にしてもらっても良いですか?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyPy2 (7.3.0) を従来どおり PyPy へと変換させることなどを考えると正規表現のほうはそのまま保っておくべきと考えました。
Fortran(GNU Fortran 9.2.1) に関してはイレギュラー扱いということで starts_with を使って判定するようにしてみました。
また、言語をsimplifyする部分のロジックを関数に切り出して単体テストを行うようにしました。
いくつかテストケースを書いていますが、過不足があったら教えていただけると助かります。

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すみません、たぶん寝ながら正規表現書いてました… \d*\s*\(.*\) でどうでしょう?

関数に切り出すのはめっちゃ良いと思います!ありがとうございます…!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その正規表現で良さそうですね!修正しました。

@kenkoooo kenkoooo merged commit cca1f6d into kenkoooo:master Aug 22, 2020
@magurotuna magurotuna deleted the language-count-client-sqlx branch August 22, 2020 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants