mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 01:55:40 +00:00
feat: store pow performance statistics against statistics
This commit is contained in:
@@ -250,6 +250,30 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||
|
||||
/// fetch PoWConfig confirms
|
||||
async fn fetch_confirm(&self, user: &str, key: &str) -> DBResult<Vec<i64>>;
|
||||
|
||||
/// record PoW timing
|
||||
async fn analysis_save(
|
||||
&self,
|
||||
captcha_id: &str,
|
||||
d: &PerformanceAnalytics,
|
||||
) -> DBResult<()>;
|
||||
|
||||
/// fetch PoW analytics
|
||||
async fn analytics_fetch(
|
||||
&self,
|
||||
captcha_id: &str,
|
||||
) -> DBResult<Vec<PerformanceAnalytics>>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)]
|
||||
/// Proof-of-Work CAPTCHA performance analytics
|
||||
pub struct PerformanceAnalytics {
|
||||
/// time taken to generate proof
|
||||
pub time: u32,
|
||||
/// difficulty factor for which the proof was generated
|
||||
pub difficulty_factor: u32,
|
||||
/// worker/client type: wasm, javascript, python, etc.
|
||||
pub worker_type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)]
|
||||
|
||||
@@ -260,6 +260,14 @@ pub async fn database_works<'a, T: MCDatabase>(
|
||||
db.record_solve(c.key).await.unwrap();
|
||||
db.record_confirm(c.key).await.unwrap();
|
||||
|
||||
let analytics = PerformanceAnalytics {
|
||||
time: 0,
|
||||
difficulty_factor: 0,
|
||||
worker_type: "wasm".into(),
|
||||
};
|
||||
db.analysis_save(c.key, &analytics).await.unwrap();
|
||||
assert_eq!(db.analytics_fetch(c.key).await.unwrap(), vec![analytics]);
|
||||
|
||||
assert_eq!(db.fetch_solve(p.username, c.key).await.unwrap().len(), 1);
|
||||
assert_eq!(
|
||||
db.fetch_config_fetched(p.username, c.key)
|
||||
|
||||
Reference in New Issue
Block a user