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

feat: define db method to get all psuedo IDs with pagination

This commit is contained in:
Aravinth Manivannan 2023-10-20 00:18:29 +05:30
parent d5617c7ec7
commit d4534c1c43
No known key found for this signature in database
GPG key ID: F8F50389936984FF
6 changed files with 113 additions and 10 deletions
db/db-sqlx-postgres/src

View file

@ -994,12 +994,8 @@ impl MCDatabase for Database {
&self,
captcha_id: &str,
) -> DBResult<String> {
struct ID {
psuedo_id: String,
}
let res = sqlx::query_as!(
ID,
PsuedoID,
"SELECT psuedo_id FROM
mcaptcha_psuedo_campaign_id
WHERE
@ -1078,6 +1074,29 @@ impl MCDatabase for Database {
Ok(())
}
/// Get all psuedo IDs
async fn analytics_get_all_psuedo_ids(&self, page: usize) -> DBResult<Vec<String>> {
const LIMIT: usize = 50;
let offset = LIMIT * page;
let mut res = sqlx::query_as!(
PsuedoID,
"
SELECT
psuedo_id
FROM
mcaptcha_psuedo_campaign_id
ORDER BY ID ASC LIMIT $1 OFFSET $2;",
LIMIT as i64,
offset as i64
)
.fetch_all(&self.pool)
.await
.map_err(|e| map_row_not_found_err(e, DBError::CaptchaNotFound))?;
Ok(res.drain(0..).map(|r| r.psuedo_id).collect())
}
}
#[derive(Clone)]
@ -1125,6 +1144,10 @@ impl From<InnerNotification> for Notification {
}
}
struct PsuedoID {
psuedo_id: String,
}
#[derive(Clone)]
struct InternaleCaptchaConfig {
config_id: i32,