summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/model.rs23
-rw-r--r--src/db/queries.rs12
2 files changed, 28 insertions, 7 deletions
diff --git a/src/db/model.rs b/src/db/model.rs
index e962d6f..dfc1f8b 100644
--- a/src/db/model.rs
+++ b/src/db/model.rs
@@ -21,6 +21,29 @@ pub struct UpstreamPin {
pub commit: String,
}
+/// A row of the Stage B cache (§5.2): the version that resolution produced,
+/// with the pins it was computed from.
+///
+/// This lives with the schema because the table lives here — the persistence
+/// layer must not name a type from the module that owns VCS probing, which is
+/// the dependency pointing the wrong way (§6 M-6). `watch::upstream::StageB`
+/// is this plus `cached`, and that extra field is the reason the two are not
+/// the same type: "was this answer a cache hit?" is a fact about the resolution
+/// that just happened, not a column.
+#[derive(Debug, Clone)]
+pub struct StageBCacheRow {
+ pub epoch: String,
+ pub pkgver: String,
+ pub pkgrel: String,
+ pub pins: Vec<UpstreamPin>,
+}
+
+impl StageBCacheRow {
+ pub fn version(&self) -> String {
+ crate::pkgver::full_version(&self.epoch, &self.pkgver, &self.pkgrel)
+ }
+}
+
/// A source entry with the digest *we* computed, regardless of what the
/// PKGBUILD declares (§5.3).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
diff --git a/src/db/queries.rs b/src/db/queries.rs
index ffb2520..b768f83 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -957,7 +957,7 @@ pub fn insert_artifact_in(tx: &rusqlite::Transaction<'_>, a: &NewArtifact<'_>) -
// --------------------------------------------------------- stage B cache --
/// Exact cache hit: same recipe, same upstream tips (§5.2).
-pub fn stage_b_cache_get(db: &Db, pkgbase_id: i64, recipe_hash: &str, tip_hash: &str) -> Result<Option<crate::watch::upstream::StageB>> {
+pub fn stage_b_cache_get(db: &Db, pkgbase_id: i64, recipe_hash: &str, tip_hash: &str) -> Result<Option<StageBCacheRow>> {
let (rh, th) = (recipe_hash.to_string(), tip_hash.to_string());
db.read(move |c| {
use rusqlite::OptionalExtension;
@@ -975,18 +975,17 @@ pub fn stage_b_cache_get(db: &Db, pkgbase_id: i64, recipe_hash: &str, tip_hash:
},
)
.optional()?
- .map(|(epoch, pkgver, pkgrel, pins_json)| crate::watch::upstream::StageB {
+ .map(|(epoch, pkgver, pkgrel, pins_json)| StageBCacheRow {
epoch,
pkgver,
pkgrel,
pins: serde_json::from_str(&pins_json).unwrap_or_default(),
- cached: true,
}))
})
}
/// The most recent answer for this pkgbase, if it is inside the cooldown window.
-pub fn stage_b_recent(db: &Db, pkgbase_id: i64, cooldown_secs: i64) -> Result<Option<crate::watch::upstream::StageB>> {
+pub fn stage_b_recent(db: &Db, pkgbase_id: i64, cooldown_secs: i64) -> Result<Option<StageBCacheRow>> {
let cutoff = crate::time::secs_ago(cooldown_secs);
db.read(move |c| {
use rusqlite::OptionalExtension;
@@ -1005,12 +1004,11 @@ pub fn stage_b_recent(db: &Db, pkgbase_id: i64, cooldown_secs: i64) -> Result<Op
},
)
.optional()?
- .map(|(epoch, pkgver, pkgrel, pins_json)| crate::watch::upstream::StageB {
+ .map(|(epoch, pkgver, pkgrel, pins_json)| StageBCacheRow {
epoch,
pkgver,
pkgrel,
pins: serde_json::from_str(&pins_json).unwrap_or_default(),
- cached: true,
}))
})
}
@@ -1020,7 +1018,7 @@ pub fn stage_b_cache_put(
pkgbase_id: i64,
recipe_hash: &str,
tip_hash: &str,
- r: &crate::watch::upstream::StageB,
+ r: &StageBCacheRow,
) -> Result<()> {
let (rh, th) = (recipe_hash.to_string(), tip_hash.to_string());
let (epoch, pkgver, pkgrel) = (r.epoch.clone(), r.pkgver.clone(), r.pkgrel.clone());