Skip to content

Commit

Permalink
Merge pull request #157 from mCaptcha/fix-154
Browse files Browse the repository at this point in the history
fix: exit loop when paginated DB query in easy PoW auto-enhance loop returns empty array
  • Loading branch information
realaravinth committed Mar 24, 2024
2 parents cb72b0a + 3a7e71b commit 581e6f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ enable_stats = true

[captcha.default_difficulty_strategy]
avg_traffic_difficulty = 50000 # almost instant solution
#avg_traffic_time = 1 # almost instant solution
avg_traffic_time = 1 # almost instant solution
peak_sustainable_traffic_difficulty = 3000000 # roughly 1.5s
#peak_sustainable_traffic_time = 3
peak_sustainable_traffic_time = 3
broke_my_site_traffic_difficulty = 5000000 # greater than 3.5s
#broke_my_site_traffic_time = 5
broke_my_site_traffic_time = 5
duration = 30 # cooldown period in seconds

[database]
Expand Down
4 changes: 4 additions & 0 deletions src/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ impl UpdateEasyCaptcha {
}

let mut patterns = data.db.get_all_easy_captchas(limit, offset).await?;
if patterns.is_empty() {
break;
}
for pattern in patterns.drain(0..) {
if !Self::can_run(rx) {
return Ok(());
Expand Down Expand Up @@ -85,6 +88,7 @@ impl UpdateEasyCaptcha {
}
page += 1;
}
Ok(())
}

fn can_run(rx: &mut Receiver<()>) -> bool {
Expand Down

0 comments on commit 581e6f9

Please sign in to comment.