summaryrefslogtreecommitdiffstats
path: root/src/db/mod.rs
diff options
context:
space:
mode:
authordev <dev@localhost>2026-11-20 17:26:52 +0000
committerdev <dev@localhost>2026-11-20 17:26:52 +0000
commit154f6f6dd284c11da82cf1188ff8549db6459228 (patch)
tree484edb3f9a77156df8dce7c2f3acaf443b014f89 /src/db/mod.rs
parent8cd32e5309b14f5264813e5f2ce6ecdb5aa41fb4 (diff)
downloadaur-build-154f6f6dd284c11da82cf1188ff8549db6459228.tar.gz
aur-build-154f6f6dd284c11da82cf1188ff8549db6459228.zip
db: close what nothing reaches, and say what cannot be closed
db handed out 226 items and 36 of them were named by nobody at all — not by the crate, not by the tests. Making them private is the whole of this commit, but the interesting part is what the compiler said afterwards. Twenty-five closed cleanly. Eleven did not, and they are the ones worth writing down: AuditRow, NoticeRow, PackageRow, Subscription, StepRow, Unbuilt, OpenReview, ReviewSubject, Migration, Writer, predecessors. None is named outside db, yet none can be made private, because a public query returns them and callers bind them with `let` and call methods on them. They are load-bearing and invisible to a name search. So the census's `dead` count means "the name is never written outside the module", which is a lead rather than a verdict, and the census now says so: the way to find out which flagged items are real is to privatize them and let rustc answer. Those eleven are budgeted with that reason, not zeroed to make a number look good. Nineteen items turned out to be dead code rather than merely unexported — set_release, set_candidate, set_pkgbase, set_profile, set_kind, current_state, index_pkgbase_drift, wal_stats, call_for_tests, put_notice, is_ours, list_pkgbases, set_unpinable, artifact_id_by_digest_in, subscription_poll_interval, the four never-emitted notice kinds, and StateEnum::as_str, which the impl_state_enum macro was required to define for all five enums while nothing called it through the trait. Privatizing is what proved they were unused; leaving them private-but-present would have just hidden dead code behind a narrower address. Ten items became pub(crate): the Writer actor's call/tx/send surface, Readers, the StateEnum trait, json_or, predecessors, DEFAULT_SETTINGS. `Db.readers` was named nowhere outside db, so the field closed with the type. db: 226 pub / 36 dead-only -> 201 pub / 11 dead-only. 277 passed / 0 failed, clippy -D warnings clean, schema_ownership and architecture green.
Diffstat (limited to 'src/db/mod.rs')
-rw-r--r--src/db/mod.rs67
1 files changed, 26 insertions, 41 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs
index d4befcc..13d7d9d 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -25,32 +25,32 @@ mod subscriptions;
mod world;
pub use migrations::MIGRATIONS;
+pub(crate) use model::StateEnum;
+pub(crate) use model::json_or;
pub use model::{
- BUILD_STEPS, BuildState, CandidateRow, CandidateState, Identity, Recipe, ReleaseRow,
- ReleaseState, SourceDigest, SourceEntry, StageBCacheRow, StateEnum, StepState,
- SubscriptionState, UpstreamPin, WorldMember, candidate_kind, json_or, notice_kind,
+ BUILD_STEPS, BuildState, CandidateRow, CandidateState,
+ Identity, Recipe, ReleaseRow, ReleaseState,
+ SourceDigest, SourceEntry, StageBCacheRow, StepState,
+ SubscriptionState, UpstreamPin, WorldMember, candidate_kind,
+ notice_kind,
};
-pub use audit::{AuditEntry, AuditRow, audit, audit_in, audit_system, list_audit};
-pub use invariants::{Unbuilt, approved_but_unbuilt, index_pkgbase_drift, unapproved_index_entries};
+pub use audit::{AuditEntry, audit, audit_in, audit_system, list_audit};
+pub use invariants::{approved_but_unbuilt, unapproved_index_entries};
pub use metrics::{
artifact_bytes_served, build_state_counts, count_index_packages, count_pending_reviews,
- count_published_releases, count_subscriptions, count_unacknowledged_notices,
- last_gc_age_secs, last_poll_age_secs, oldest_queued_age_secs, pending_review_ages_secs,
+ count_published_releases, count_subscriptions, count_unacknowledged_notices, last_gc_age_secs,
+ last_poll_age_secs, oldest_queued_age_secs, pending_review_ages_secs,
};
-pub use notices::{NoticeRow, acknowledge_notice, list_notices, put_notice, put_notice_once};
+pub use notices::{acknowledge_notice, list_notices, put_notice_once};
pub use packages::{
- PackageRow, accepted_recipe, builds_for_pkgbase, index_artifact, index_packages,
- index_version, is_ours, our_package_names,
-};
-pub use pkgbases::{
- Pkgbase, cas_accepted_release, get_pkgbase, get_pkgbase_by_id, list_pkgbases, set_aur_head,
- set_unpinable,
+ accepted_recipe, builds_for_pkgbase, index_artifact, index_packages,
+ index_version, our_package_names,
};
+pub use pkgbases::{Pkgbase, cas_accepted_release, get_pkgbase, get_pkgbase_by_id, set_aur_head};
pub use publish_writes::{
- NewRelease, accepted_pointer_in, artifact_id_by_digest_in, artifact_path,
- cas_accepted_release_in, insert_package_in, insert_release_in, remove_index_packages_in,
- remove_package_by_name_in,
+ NewRelease, accepted_pointer_in, artifact_path, cas_accepted_release_in,
+ insert_package_in, insert_release_in, remove_index_packages_in, remove_package_by_name_in,
};
pub use releases::{
accepted_release, all_published_releases, release_by_id, releases_for_pkgbase,
@@ -58,19 +58,19 @@ pub use releases::{
};
pub use repos::{ensure_repo, repo_id};
pub use retention::{
- ArtifactPaths, mark_release_purged, pkgbase_release_pointers, published_release_ids,
- record_gc_run, release_artifact_paths, serving_release_ids,
+ mark_release_purged, pkgbase_release_pointers, published_release_ids, record_gc_run,
+ release_artifact_paths, serving_release_ids,
};
pub use settings::{all_settings, set_setting, setting, setting_i64};
pub use snapshots::{SnapshotRow, put_snapshot, snapshot_by_commit, snapshot_by_id};
pub use stage_b::{stage_b_cache_get, stage_b_cache_put, stage_b_recent};
pub use staleness::{
- NewArtifact, approval_note, candidate_snapshot_id, index_recipes, insert_artifact_in,
- published_world_members, put_source_cache, served_vs_offered_pkgvers, source_cache_path,
- subscription_poll_interval,
+ NewArtifact, approval_note, candidate_snapshot_id, index_recipes,
+ insert_artifact_in, published_world_members, put_source_cache, served_vs_offered_pkgvers,
+ source_cache_path,
};
pub use subscriptions::{
- Subscription, due_subscriptions, get_subscription, list_subscriptions, note_check,
+ due_subscriptions, get_subscription, list_subscriptions, note_check,
set_subscription_state, subscribe,
};
pub use world::{put_world_snapshot, world_members};
@@ -88,7 +88,6 @@ pub(crate) fn state_col<T: StateEnum>(col: usize, text: &str) -> rusqlite::Resul
})
}
-
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
@@ -197,7 +196,7 @@ impl Writer {
&self.path
}
- pub fn is_alive(&self) -> bool {
+ fn is_alive(&self) -> bool {
self.alive.load(Ordering::SeqCst)
}
@@ -256,16 +255,9 @@ impl Writer {
{
self.tx(f)
}
-
- pub fn call_for_tests<T>(&self, f: impl FnOnce(&mut Connection) -> Result<T> + Send + 'static) -> Result<T>
- where
- T: Send + 'static,
- {
- self.call(f)
- }
}
-pub struct Readers {
+pub(crate) struct Readers {
path: PathBuf,
}
@@ -300,7 +292,7 @@ impl Readers {
#[derive(Clone)]
pub struct Db {
pub writer: Arc<Writer>,
- pub readers: Arc<Readers>,
+ pub(crate) readers: Arc<Readers>,
}
impl Db {
@@ -338,10 +330,3 @@ pub fn schema_version(path: &Path) -> Result<i64> {
.map_err(|e| Error::db(format!("{} has no schema version: {e}", path.display())))
}
-pub fn wal_stats(db: &Db) -> (u64, u64) {
- let db_file = std::fs::metadata(db.writer.path()).map(|m| m.len()).unwrap_or(0);
- let mut wal = db.writer.path().as_os_str().to_os_string();
- wal.push("-wal");
- let wal_file = std::fs::metadata(&wal).map(|m| m.len()).unwrap_or(0);
- (db_file, wal_file)
-}