summaryrefslogtreecommitdiffstats
path: root/src/db/candidates.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/candidates.rs')
-rw-r--r--src/db/candidates.rs34
1 files changed, 0 insertions, 34 deletions
diff --git a/src/db/candidates.rs b/src/db/candidates.rs
index 631bf42..df145ac 100644
--- a/src/db/candidates.rs
+++ b/src/db/candidates.rs
@@ -4,7 +4,6 @@ use crate::db::{CandidateRow, CandidateState, Db};
use crate::error::{Error, Result};
use crate::time;
-/// The columns `row_to_candidate` reads, spelled once (§6 m-3).
const CANDIDATE_COLS: &str = "c.id, c.pkgbase_id, c.base_release_id, c.kind, c.snapshot_id, c.epoch, c.pkgver, \
c.pkgrel, c.upstream_pins_json, c.source_digests_json, c.identity_hash, c.diff_digest, \
c.revision, c.viewed_at, c.risk_level, c.risk_signals_json, c.missing_deps_json, c.state, \
@@ -36,7 +35,6 @@ fn row_to_candidate(r: &Row<'_>) -> rusqlite::Result<CandidateRow> {
})
}
-/// The fields a new candidate row carries, beyond its pkgbase and its base.
#[derive(Debug, Clone)]
pub struct NewCandidate {
pub snapshot_id: i64,
@@ -49,13 +47,11 @@ pub struct NewCandidate {
}
impl NewCandidate {
- /// The `epoch:pkgver-pkgrel` this candidate would publish.
pub fn version(&self) -> String {
crate::pkgver::full_version(&self.epoch, &self.pkgver, &self.pkgrel)
}
}
-/// The open review of a pkgbase — as much of it as the collapse rules need.
#[derive(Debug, Clone)]
pub struct OpenReview {
pub id: i64,
@@ -65,8 +61,6 @@ pub struct OpenReview {
}
impl OpenReview {
- /// Has a human opened this review yet? That timestamp is what decides
- /// whether a newer detection collapses or supersedes (§7.1).
pub fn viewed(&self) -> bool {
self.viewed_at.is_some()
}
@@ -74,8 +68,6 @@ impl OpenReview {
// ------------------------------------------------------------------ in-tx --
-/// Everything the approval gate has to look at to decide, read in one statement
-/// so the check cannot straddle two snapshots of the database.
#[derive(Debug, Clone)]
pub struct ReviewSubject {
pub id: i64,
@@ -83,9 +75,7 @@ pub struct ReviewSubject {
pub state: CandidateState,
pub identity_hash: String,
pub diff_digest: String,
- /// The release this review was opened against (I2).
pub base_release_id: Option<i64>,
- /// What the pkgbase accepts now — the other half of the I2 check.
pub current_base_release_id: Option<i64>,
pub risk_level: String,
pub pkgbase: String,
@@ -116,10 +106,6 @@ pub fn review_subject_in(tx: &Transaction<'_>, candidate_id: i64) -> Result<Opti
.optional()?)
}
-/// Take a candidate out of the open state: approved, rejected or superseded.
-///
-/// The write is a compare-and-swap on [`CandidateState`]: a decided review is never
-/// re-decided, so an approval racing a rejection fails instead of overwriting.
pub fn resolve_in(tx: &Transaction<'_>, id: i64, to: CandidateState, at: &str) -> Result<()> {
let froms = CandidateState::predecessors(to);
let placeholders = froms.iter().map(|_| "?").collect::<Vec<_>>().join(",");
@@ -144,8 +130,6 @@ pub fn resolve_in(tx: &Transaction<'_>, id: i64, to: CandidateState, at: &str) -
Ok(())
}
-/// A candidate's state, read inside a transaction (the reject path needs it
-/// before it writes).
pub fn state_in(tx: &Transaction<'_>, id: i64) -> Result<Option<CandidateState>> {
Ok(tx
.query_row("SELECT state FROM candidate WHERE id=?1", params![id], |r| {
@@ -160,7 +144,6 @@ pub fn identity_in(tx: &Transaction<'_>, id: i64) -> Result<Option<String>> {
.optional()?)
}
-/// The risk level recorded at review time, if the candidate exists.
pub fn risk_level(db: &Db, id: i64) -> Result<Option<String>> {
db.read(|c| {
Ok(c.query_row("SELECT risk_level FROM candidate WHERE id=?1", params![id], |r| r.get::<_, String>(0))
@@ -168,7 +151,6 @@ pub fn risk_level(db: &Db, id: i64) -> Result<Option<String>> {
})
}
-/// The pkgbase's open review, if it has one (I7: at most one).
pub fn open_in(tx: &Transaction<'_>, pkgbase_id: i64) -> Result<Option<OpenReview>> {
Ok(tx
.query_row(
@@ -187,8 +169,6 @@ pub fn open_in(tx: &Transaction<'_>, pkgbase_id: i64) -> Result<Option<OpenRevie
.optional()?)
}
-/// Write a newer detection into the open review: same row, same base, one more
-/// revision, and the stale diff rendering dropped so it cannot be approved.
pub fn collapse_in(tx: &mut Transaction<'_>, open: &OpenReview, nc: &NewCandidate) -> Result<i64> {
let revision = open.revision + 1;
tx.execute(
@@ -212,14 +192,11 @@ pub fn collapse_in(tx: &mut Transaction<'_>, open: &OpenReview, nc: &NewCandidat
Ok(revision)
}
-/// Freeze a reviewed candidate as `superseded` so a fresh review can open.
pub fn supersede_in(tx: &Transaction<'_>, id: i64) -> Result<()> {
let at = time::now();
resolve_in(tx, id, CandidateState::Superseded, &at)
}
-/// Has this exact identity been rejected before? If so the watcher stays quiet
-/// until a human re-opens it (§7.1).
pub fn rejected_before_in(tx: &Transaction<'_>, pkgbase_id: i64, identity_hash: &str) -> Result<bool> {
Ok(tx
.query_row(
@@ -232,8 +209,6 @@ pub fn rejected_before_in(tx: &Transaction<'_>, pkgbase_id: i64, identity_hash:
.is_some())
}
-/// Has this identity been recorded at all — approved, superseded, anything?
-/// Then the detection said nothing new.
pub fn recorded_before_in(tx: &Transaction<'_>, pkgbase_id: i64, identity_hash: &str) -> Result<bool> {
Ok(tx
.query_row(
@@ -246,7 +221,6 @@ pub fn recorded_before_in(tx: &Transaction<'_>, pkgbase_id: i64, identity_hash:
.is_some())
}
-/// Open a candidate row in `pending_review`.
pub fn insert_in(
tx: &mut Transaction<'_>,
pkgbase_id: i64,
@@ -277,7 +251,6 @@ pub fn insert_in(
// ------------------------------------------------------------------ reads --
-/// Every candidate regardless of state, newest first (`aur-build reviews --all`).
pub fn all(db: &Db) -> Result<Vec<CandidateRow>> {
let sql = format!("SELECT {CANDIDATE_COLS} FROM candidate c JOIN pkgbase b ON b.id = c.pkgbase_id ORDER BY c.detected_at DESC LIMIT 500");
db.read(move |c| {
@@ -291,7 +264,6 @@ pub fn all(db: &Db) -> Result<Vec<CandidateRow>> {
})
}
-/// The reviews waiting for a decision, riskiest first.
pub fn pending(db: &Db) -> Result<Vec<CandidateRow>> {
let sql = format!(
"SELECT {CANDIDATE_COLS} FROM candidate c JOIN pkgbase b ON b.id = c.pkgbase_id \
@@ -316,7 +288,6 @@ pub fn by_id(db: &Db, id: i64) -> Result<Option<CandidateRow>> {
})
}
-/// Open reviews for a pkgbase (usually zero or one, by I7).
pub fn open_reviews_for(db: &Db, pkgbase_id: i64) -> Result<Vec<CandidateRow>> {
let sql = format!(
"SELECT {CANDIDATE_COLS} FROM candidate c JOIN pkgbase b ON b.id = c.pkgbase_id \
@@ -335,8 +306,6 @@ pub fn open_reviews_for(db: &Db, pkgbase_id: i64) -> Result<Vec<CandidateRow>> {
// ---------------------------------------------------------------- writes --
-/// Mark a candidate `viewed` the first time a human opens it. That timestamp is
-/// what decides whether a later detection collapses or supersedes (§7.1).
pub fn mark_viewed(db: &Db, id: i64) -> Result<()> {
let at = time::now();
db.writer.tx(move |tx| {
@@ -348,8 +317,6 @@ pub fn mark_viewed(db: &Db, id: i64) -> Result<()> {
})
}
-/// §7.1: a rejection can be re-opened. The rejected row is retired so it stops
-/// suppressing the identity, and the next detection opens a fresh review.
pub fn reopen_rejected(db: &Db, id: i64) -> Result<()> {
let at = time::now();
db.writer.tx(move |tx| {
@@ -364,7 +331,6 @@ pub fn reopen_rejected(db: &Db, id: i64) -> Result<()> {
})
}
-/// Record the risk assessment computed at review time.
pub fn set_risk(db: &Db, id: i64, level: &str, signals: &[String]) -> Result<()> {
let lvl = level.to_string();
let sig = serde_json::to_string(signals)?;