diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:33:17 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:33:17 +0000 |
| commit | 4304b0f336ddba7b4ec6780795059ff2066d105b (patch) | |
| tree | 10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /src/db/mod.rs | |
| parent | e757979f1a2afdbe7146066345bb9acd19d3b151 (diff) | |
| download | aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.tar.gz aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.zip | |
comments: keep only what the code cannot show
Stripped every comment that described what an item does, documented its
arguments or fields, or cited the design docs (§n, I-n, m-n, decision n).
2247 comments down to 83.
What survives: the section dividers that segment the large modules, the
secret-handling warnings, the agent wire-frame directions, and the few notes
without which the code they attach to reads as redundant, reorderable, or
unsound.
Diffstat (limited to 'src/db/mod.rs')
| -rw-r--r-- | src/db/mod.rs | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs index c271fe7..95833be 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -8,8 +8,6 @@ pub mod queries; pub use migrations::MIGRATIONS; pub use model::*; -/// Parse a state column into one of the state enums. A value the code does not -/// recognise fails the row instead of becoming a default. pub(crate) fn state_col<T: StateEnum>(col: usize, text: &str) -> rusqlite::Result<T> { T::parse(text).ok_or_else(|| { rusqlite::Error::FromSqlConversionFailure( @@ -35,7 +33,6 @@ use rusqlite::Connection; use crate::config::Config; use crate::error::{Error, Result}; -/// Open a connection with the pragmas every connection needs. fn open(path: &Path, read_only: bool) -> Result<Connection> { let conn = if read_only { Connection::open_with_flags( @@ -56,14 +53,12 @@ fn configure(conn: &Connection, read_only: bool) -> Result<()> { .and_then(|_| conn.pragma_update(None, "foreign_keys", "ON")) .map_err(|e| Error::db(e.to_string()))?; if !read_only { - // Durability of the approval trail is worth the fsync (§11a). conn.pragma_update(None, "synchronous", "FULL") .map_err(|e| Error::db(e.to_string()))?; } Ok(()) } -/// Apply pending migrations. Must run before the writer actor starts. pub fn migrate(path: &Path) -> Result<u32> { let mut conn = open(path, false)?; let mut applied = 0u32; @@ -101,9 +96,6 @@ enum Msg { Shutdown, } -/// Handle on the single writer thread. -/// -/// Cheap to clone; every clone talks to the same actor. pub struct Writer { tx: Sender<Msg>, path: PathBuf, @@ -111,7 +103,6 @@ pub struct Writer { } impl Writer { - /// Spawn the writer actor thread. pub fn start(path: &Path) -> Result<Self> { let conn = open(path, false)?; let (tx, rx) = unbounded::<Msg>(); @@ -129,7 +120,6 @@ impl Writer { Msg::Shutdown => break, } } - // Best-effort WAL checkpoint on the way out. let _ = conn.pragma_update(None, "wal_checkpoint", "TRUNCATE"); alive_thread.store(false, Ordering::SeqCst); }) @@ -145,13 +135,6 @@ impl Writer { self.alive.load(Ordering::SeqCst) } - /// Run `f` on the write connection and wait for its result. No transaction - /// may span a build step: `f` should be short. - /// - /// `pub(crate)`, not `pub`: the schema has one owner, this module (§6 M-1). - /// Inside the crate the convention is enforced by - /// `tests/schema_ownership.rs`, which fails the build if a SQL statement - /// appears outside `src/db/`. pub(crate) fn call<T>(&self, f: impl FnOnce(&mut Connection) -> Result<T> + Send + 'static) -> Result<T> where T: Send + 'static, @@ -165,7 +148,6 @@ impl Writer { .map_err(|_| Error::db("writer actor gone"))? } - /// Run `f` inside a single `BEGIN IMMEDIATE` transaction. pub(crate) fn tx<T>( &self, f: impl FnOnce(&mut rusqlite::Transaction<'_>) -> Result<T> + Send + 'static, @@ -183,7 +165,6 @@ impl Writer { }) } - /// Fire-and-forget write (audit rows, bookkeeping where the result is unused). pub(crate) fn send(&self, f: BoxedCall) -> Result<()> { if !self.is_alive() { return Err(Error::db("writer actor gone")); @@ -198,10 +179,6 @@ impl Writer { } } -/// The raw-SQL door, open only for the test harness (§6 M-9). A fixture -/// sometimes has to reach a state the typed API only reaches through several -/// steps, but that is not a reason to leave the door unlocked in the binary an -/// operator runs. #[cfg(feature = "test-support")] impl Writer { pub fn tx_for_tests<T>( @@ -222,9 +199,6 @@ impl Writer { } } -/// Thread-local read-only connection pool: one connection per thread per -/// database file. HTTP handlers and watchers use this; they never touch the -/// write connection. pub struct Readers { path: PathBuf, } @@ -238,7 +212,6 @@ impl Readers { Self { path: path.to_path_buf() } } - /// Run `f` against this thread's read-only connection. pub fn with<T>(&self, f: impl FnOnce(&Connection) -> Result<T>) -> Result<T> { let path = self.path.clone(); POOL.with(|pool| { @@ -258,7 +231,6 @@ impl Readers { } } -/// A handle bundling the writer with a reader factory; passed around as `App`. #[derive(Clone)] pub struct Db { pub writer: Arc<Writer>, @@ -279,13 +251,11 @@ impl Db { }) } - /// Convenience: read-only query against the shared reader pool. pub fn read<T>(&self, f: impl FnOnce(&Connection) -> Result<T>) -> Result<T> { self.readers.with(f) } } -/// Consistent snapshot for backups: `VACUUM INTO`, never `cp` of a live WAL db. pub fn backup_to(writer: &Writer, dest: &Path) -> Result<()> { let dest_s = dest.display().to_string(); writer.call(move |conn| { @@ -295,11 +265,6 @@ pub fn backup_to(writer: &Writer, dest: &Path) -> Result<()> { }) } -/// The schema version a database file reports. A backup that does not answer -/// with a migrated schema is a file, not a backup. -/// -/// Opened read-write and untouched by the connection pragmas: a WAL database -/// cannot even be opened read-only. pub fn schema_version(path: &Path) -> Result<i64> { let conn = rusqlite::Connection::open(path) .map_err(|e| Error::db(format!("{} does not open: {e}", path.display())))?; |
