systemprompt_analytics/repository/fingerprint/
mod.rs1mod mutations;
13mod queries;
14
15use std::sync::Arc;
16
17use sqlx::PgPool;
18use systemprompt_database::DbPool;
19
20pub const MAX_SESSIONS_PER_FINGERPRINT: i32 = 5;
21pub const HIGH_REQUEST_THRESHOLD: i64 = 100;
22pub const HIGH_VELOCITY_RPM: f32 = 10.0;
23pub const SUSTAINED_VELOCITY_MINUTES: i32 = 60;
24pub const ABUSE_THRESHOLD_FOR_BAN: i32 = 3;
25
26#[derive(Clone)]
27pub struct FingerprintRepository {
28 pool: Arc<PgPool>,
29 write_pool: Arc<PgPool>,
30 sessions: systemprompt_traits::DynSessionStore,
31}
32
33impl FingerprintRepository {
34 pub fn new(db: &DbPool, sessions: systemprompt_traits::DynSessionStore) -> Self {
35 let pool = db.pool();
36 let write_pool = db.write_pool();
37 Self {
38 pool,
39 write_pool,
40 sessions,
41 }
42 }
43}
44
45impl std::fmt::Debug for FingerprintRepository {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 f.debug_struct("FingerprintRepository")
48 .finish_non_exhaustive()
49 }
50}