diff options
Diffstat (limited to 'crates/turtle/src/atuin_server/database/db')
| -rw-r--r-- | crates/turtle/src/atuin_server/database/db/mod.rs | 13 | ||||
| -rw-r--r-- | crates/turtle/src/atuin_server/database/db/wrappers.rs | 16 |
2 files changed, 8 insertions, 21 deletions
diff --git a/crates/turtle/src/atuin_server/database/db/mod.rs b/crates/turtle/src/atuin_server/database/db/mod.rs index 4ec51bf1..5b3c169b 100644 --- a/crates/turtle/src/atuin_server/database/db/mod.rs +++ b/crates/turtle/src/atuin_server/database/db/mod.rs @@ -17,13 +17,13 @@ mod wrappers; const MIN_PG_VERSION: u32 = 14; #[derive(Clone)] -pub struct Database { +pub struct ServerPostgres { pool: sqlx::Pool<sqlx::postgres::Postgres>, /// Optional read replica pool for read-only queries read_pool: Option<sqlx::Pool<sqlx::postgres::Postgres>>, } -impl Database { +impl ServerPostgres { /// Returns the appropriate pool for read operations. /// Uses read_pool if available, otherwise falls back to the primary pool. fn read_pool(&self) -> &sqlx::Pool<sqlx::postgres::Postgres> { @@ -31,7 +31,7 @@ impl Database { } } -impl Database { +impl ServerPostgres { pub(crate) async fn new(settings: &DbSettings) -> DbResult<Self> { let pool = PgPoolOptions::new() .max_connections(100) @@ -138,7 +138,7 @@ impl Database { .entry((i.host.id, &i.tag)) .and_modify(|e| { if i.idx > *e { - *e = i.idx + *e = i.idx; } }) .or_insert(i.idx); @@ -229,7 +229,8 @@ impl Database { // 3. If we don't use the cache, read from the store table // IDX_CACHE_ROLLOUT should be between 0 and 100. - let idx_cache_rollout = std::env::var("IDX_CACHE_ROLLOUT").unwrap_or("0".to_string()); + let idx_cache_rollout = + std::env::var("IDX_CACHE_ROLLOUT").unwrap_or_else(|_| "0".to_string()); let idx_cache_rollout = idx_cache_rollout.parse::<f64>().unwrap_or(0.0); let use_idx_cache = rand::thread_rng().gen_bool(idx_cache_rollout / 100.0); @@ -264,7 +265,7 @@ impl Database { let mut status = RecordStatus::new(); - for i in res.iter() { + for i in &res { status.set_raw(HostId(i.0), i.1.clone(), i.2 as u64); } diff --git a/crates/turtle/src/atuin_server/database/db/wrappers.rs b/crates/turtle/src/atuin_server/database/db/wrappers.rs index 40fd5b4a..8a52d56e 100644 --- a/crates/turtle/src/atuin_server/database/db/wrappers.rs +++ b/crates/turtle/src/atuin_server/database/db/wrappers.rs @@ -1,22 +1,8 @@ -use crate::{ - atuin_common::record::{EncryptedData, Host, Record}, - atuin_server::database::models::Session, -}; +use crate::atuin_common::record::{EncryptedData, Host, Record}; use sqlx::{Row, postgres::PgRow}; -pub struct DbSession(pub Session); pub struct DbRecord(pub Record<EncryptedData>); -impl<'a> ::sqlx::FromRow<'a, PgRow> for DbSession { - fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> { - Ok(Self(Session { - id: row.try_get("id")?, - user_id: row.try_get("user_id")?, - token: row.try_get("token")?, - })) - } -} - impl<'a> ::sqlx::FromRow<'a, PgRow> for DbRecord { fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> { let timestamp: i64 = row.try_get("timestamp")?; |
