mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 10:35:39 +00:00
feat: migrate record_stats to use db_*
This commit is contained in:
@@ -16,4 +16,87 @@
|
||||
*/
|
||||
|
||||
pub mod fetch;
|
||||
pub mod record;
|
||||
//pub mod record;
|
||||
|
||||
pub use fetch::StatsUnixTimestamp;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use db_core::errors::DBResult;
|
||||
|
||||
use crate::data::Data;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Stats: std::marker::Send + std::marker::Sync + CloneStats {
|
||||
/// record PoWConfig fetches
|
||||
async fn record_fetch(&self, d: &Data, key: &str) -> DBResult<()>;
|
||||
|
||||
/// record PoWConfig solves
|
||||
async fn record_solve(&self, d: &Data, key: &str) -> DBResult<()>;
|
||||
|
||||
/// record PoWConfig confirms
|
||||
async fn record_confirm(&self, d: &Data, key: &str) -> DBResult<()>;
|
||||
}
|
||||
|
||||
/// Trait to clone MCDatabase
|
||||
pub trait CloneStats {
|
||||
/// clone DB
|
||||
fn clone_stats(&self) -> Box<dyn Stats>;
|
||||
}
|
||||
|
||||
impl<T> CloneStats for T
|
||||
where
|
||||
T: Stats + Clone + 'static,
|
||||
{
|
||||
fn clone_stats(&self) -> Box<dyn Stats> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Box<dyn CloneStats> {
|
||||
fn clone(&self) -> Self {
|
||||
self.clone()
|
||||
//(*self).clone_stats()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Debug)]
|
||||
pub struct Real;
|
||||
|
||||
#[async_trait]
|
||||
impl Stats for Real {
|
||||
/// record PoWConfig fetches
|
||||
async fn record_fetch(&self, d: &Data, key: &str) -> DBResult<()> {
|
||||
d.dblib.record_fetch(key).await
|
||||
}
|
||||
|
||||
/// record PoWConfig solves
|
||||
async fn record_solve(&self, d: &Data, key: &str) -> DBResult<()> {
|
||||
d.dblib.record_solve(key).await
|
||||
}
|
||||
|
||||
/// record PoWConfig confirms
|
||||
async fn record_confirm(&self, d: &Data, key: &str) -> DBResult<()> {
|
||||
d.dblib.record_confirm(key).await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Debug)]
|
||||
pub struct Dummy;
|
||||
|
||||
#[async_trait]
|
||||
impl Stats for Dummy {
|
||||
/// record PoWConfig fetches
|
||||
async fn record_fetch(&self, _: &Data, _: &str) -> DBResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// record PoWConfig solves
|
||||
async fn record_solve(&self, _: &Data, _: &str) -> DBResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// record PoWConfig confirms
|
||||
async fn record_confirm(&self, _: &Data, _: &str) -> DBResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user