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
6 changed files with 113 additions and 10 deletions

View File

@@ -987,12 +987,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
@@ -1069,6 +1065,28 @@ 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 ? OFFSET ?;",
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)]
@@ -1134,3 +1152,7 @@ impl From<InternaleCaptchaConfig> for Captcha {
}
}
}
struct PsuedoID {
psuedo_id: String,
}