feat: define db method to get all psuedo IDs with pagination
This commit is contained in:
parent
d5617c7ec7
commit
d4534c1c43
6 changed files with 113 additions and 10 deletions
|
@ -289,6 +289,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all psuedo IDs
|
||||
async fn analytics_get_all_psuedo_ids(&self, page: usize) -> DBResult<Vec<String>>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)]
|
||||
|
|
|
@ -258,6 +258,12 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||
.analytics_get_psuedo_id_from_capmaign_id(c.key)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
vec![psuedo_id.clone()],
|
||||
db.analytics_get_all_psuedo_ids(0).await.unwrap()
|
||||
);
|
||||
assert!(db.analytics_get_all_psuedo_ids(1).await.unwrap().is_empty());
|
||||
|
||||
db.analytics_create_psuedo_id_if_not_exists(c.key)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -267,6 +273,7 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||
.await
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
c.key,
|
||||
db.analytics_get_capmaign_id_from_psuedo_id(&psuedo_id)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"db_name": "MySQL",
|
||||
"query": "\n SELECT\n psuedo_id\n FROM\n mcaptcha_psuedo_campaign_id\n ORDER BY ID ASC LIMIT ? OFFSET ?;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "psuedo_id",
|
||||
"type_info": {
|
||||
"type": "VarString",
|
||||
"flags": "NOT_NULL | UNIQUE_KEY | NO_DEFAULT_VALUE",
|
||||
"char_set": 224,
|
||||
"max_size": 400
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e2c30dafa790b388a193ad8785c0a7d88d8e7a7558775e238fe009f478003e46"
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT\n psuedo_id\n FROM\n mcaptcha_psuedo_campaign_id\n ORDER BY ID ASC LIMIT $1 OFFSET $2;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "psuedo_id",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "d6b89b032e3a65bb5739dde8901a0d6363939bdd87739b4292dd1d88e03ce6f7"
|
||||
}
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue