1
0
Fork 0
mirror of https://github.com/mCaptcha/mCaptcha.git synced 2025-05-09 16:30:07 +03:00

feat: pagination on performance logs fetches

This commit is contained in:
Aravinth Manivannan 2023-06-28 22:54:18 +05:30
parent dc380adfcf
commit 8af09939ff
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
6 changed files with 160 additions and 98 deletions
db/db-sqlx-postgres

View file

@ -1,5 +1,45 @@
{
"db": "PostgreSQL",
"017576128f1c63aee062799a33f872457fe19f5d6429d0af312dc00c244b31cb": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int4"
},
{
"name": "time",
"ordinal": 1,
"type_info": "Int4"
},
{
"name": "difficulty_factor",
"ordinal": 2,
"type_info": "Int4"
},
{
"name": "worker_type",
"ordinal": 3,
"type_info": "Varchar"
}
],
"nullable": [
false,
false,
false,
false
],
"parameters": {
"Left": [
"Text",
"Int8",
"Int8"
]
}
},
"query": "SELECT id, time, difficulty_factor, worker_type FROM mcaptcha_pow_analytics\n WHERE \n config_id = (\n SELECT \n config_id FROM mcaptcha_config \n WHERE \n key = $1\n )\n ORDER BY ID\n OFFSET $2 LIMIT $3\n "
},
"02deb524bb12632af9b7883975f75fdc30d6775d836aff647add1dffd1a4bc00": {
"describe": {
"columns": [
@ -626,38 +666,6 @@
},
"query": "DELETE FROM mcaptcha_users WHERE name = ($1)"
},
"d4ca28f0d895ef832d5cc1bc56c17e94c33efdfe63e10f29bbe54b6841a43320": {
"describe": {
"columns": [
{
"name": "time",
"ordinal": 0,
"type_info": "Int4"
},
{
"name": "difficulty_factor",
"ordinal": 1,
"type_info": "Int4"
},
{
"name": "worker_type",
"ordinal": 2,
"type_info": "Varchar"
}
],
"nullable": [
false,
false,
false
],
"parameters": {
"Left": [
"Text"
]
}
},
"query": "SELECT time, difficulty_factor, worker_type FROM mcaptcha_pow_analytics\n WHERE \n config_id = (\n SELECT \n config_id FROM mcaptcha_config \n WHERE \n key = $1\n )\n ORDER BY ID"
},
"d7dd6cd6a7626e79c62377b2d59115067c5851ec044911ff8833779a08bbb8f7": {
"describe": {
"columns": [],

View file

@ -906,7 +906,7 @@ impl MCDatabase for Database {
async fn analysis_save(
&self,
captcha_id: &str,
d: &PerformanceAnalytics,
d: &CreatePerformanceAnalytics,
) -> DBResult<()> {
let _ = sqlx::query!(
"INSERT INTO mcaptcha_pow_analytics
@ -927,8 +927,11 @@ impl MCDatabase for Database {
async fn analytics_fetch(
&self,
captcha_id: &str,
limit: usize,
offset: usize,
) -> DBResult<Vec<PerformanceAnalytics>> {
struct P {
id: i32,
time: i32,
difficulty_factor: i32,
worker_type: String,
@ -940,13 +943,14 @@ impl MCDatabase for Database {
time: v.time as u32,
difficulty_factor: v.difficulty_factor as u32,
worker_type: v.worker_type,
id: v.id as usize,
}
}
}
let mut c = sqlx::query_as!(
P,
"SELECT time, difficulty_factor, worker_type FROM mcaptcha_pow_analytics
"SELECT id, time, difficulty_factor, worker_type FROM mcaptcha_pow_analytics
WHERE
config_id = (
SELECT
@ -954,8 +958,12 @@ impl MCDatabase for Database {
WHERE
key = $1
)
ORDER BY ID",
ORDER BY ID
OFFSET $2 LIMIT $3
",
&captcha_id,
offset as i32,
limit as i32
)
.fetch_all(&self.pool)
.await