1
0
Fork 0
mirror of https://github.com/mCaptcha/mCaptcha.git synced 2025-05-01 21:00:24 +03:00

feat: create individual databases for each test

This commit is contained in:
Aravinth Manivannan 2023-11-05 00:49:06 +05:30
parent 36600e2f13
commit 321fd2e89b
No known key found for this signature in database
GPG key ID: F8F50389936984FF
7 changed files with 134 additions and 85 deletions
db/db-sqlx-postgres/src

View file

@ -1230,28 +1230,29 @@ impl MCDatabase for Database {
/// Get number of analytics entries that are under a certain duration
async fn stats_get_num_logs_under_time(&self, duration: u32) -> DBResult<usize> {
struct Count {
count: Option<i64>,
}
struct Count {
count: Option<i64>,
}
let count = sqlx::query_as!(
let count = sqlx::query_as!(
Count,
"SELECT COUNT(difficulty_factor) FROM mcaptcha_pow_analytics WHERE time <= $1;",
duration as i32,
)
.fetch_one(&self.pool)
.await
.map_err(|e| map_row_not_found_err(e, DBError::CaptchaNotFound))?;
.fetch_one(&self.pool)
.await
.map_err(|e| map_row_not_found_err(e, DBError::CaptchaNotFound))?;
Ok(count.count.unwrap_or_else(|| 0) as usize)
}
/// Get the entry at a location in the list of analytics entires under a certain time limit
/// and sorted in ascending order
async fn stats_get_entry_at_location_for_time_limit_asc(&self, duration: u32, location: u32) -> DBResult<Option<usize>> {
async fn stats_get_entry_at_location_for_time_limit_asc(
&self,
duration: u32,
location: u32,
) -> DBResult<Option<usize>> {
struct Difficulty {
difficulty_factor: Option<i32>,
}
@ -1273,13 +1274,9 @@ impl MCDatabase for Database {
{
Ok(res) => Ok(Some(res.difficulty_factor.unwrap() as usize)),
Err(sqlx::Error::RowNotFound) => Ok(None),
Err(e) => Err(map_row_not_found_err(e, DBError::CaptchaNotFound))
Err(e) => Err(map_row_not_found_err(e, DBError::CaptchaNotFound)),
}
}
}
#[derive(Clone)]

View file

@ -7,8 +7,8 @@
use std::env;
use sqlx::postgres::PgPoolOptions;
use sqlx::migrate::MigrateDatabase;
use sqlx::postgres::PgPoolOptions;
use url::Url;
use crate::*;
@ -47,7 +47,6 @@ async fn everyting_works() {
}
sqlx::Postgres::create_database(&url).await.unwrap();
let pool_options = PgPoolOptions::new().max_connections(2);
let connection_options = ConnectionOptions::Fresh(Fresh {
pool_options,