diff options
Diffstat (limited to 'src/watch/upstream.rs')
| -rw-r--r-- | src/watch/upstream.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 442647c..8d7fa4f 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -124,6 +124,28 @@ impl StageB { pub fn version(&self) -> String { crate::pkgver::full_version(&self.epoch, &self.pkgver, &self.pkgrel) } + + /// Rebuild an answer from its cache row. The `cached` flag is ours to set: + /// the row says nothing about how this call got its answer (§6 M-6). + fn from_cache(row: StageBCacheRow) -> Self { + StageB { + epoch: row.epoch, + pkgver: row.pkgver, + pkgrel: row.pkgrel, + pins: row.pins, + cached: true, + } + } + + /// The row this answer occupies in `stage_b_cache`. + fn as_row(&self) -> StageBCacheRow { + StageBCacheRow { + epoch: self.epoch.clone(), + pkgver: self.pkgver.clone(), + pkgrel: self.pkgrel.clone(), + pins: self.pins.clone(), + } + } } /// A process-wide cap on concurrent Stage B resolutions (§5.2 "a global @@ -180,7 +202,7 @@ pub fn resolve( // Cache hit: same recipe, same upstream tips. Keyed on // (pkgbase, recipe_hash, upstream_tip) exactly as §5.2 asks. if let Some(hit) = db::stage_b_cache_get(db, pb.id, recipe_hash, &tip_hash)? { - return Ok(Some(hit)); + return Ok(Some(StageB::from_cache(hit))); } // Per-pkgbase cooldown: even if the tips moved again, we do not re-resolve @@ -188,12 +210,12 @@ pub fn resolve( // is reused, so a chatty upstream cannot turn detection into a build loop. let cooldown = db::setting_i64(db, "stage_b_cooldown", 86400); if let Some(recent) = db::stage_b_recent(db, pb.id, cooldown)? { - return Ok(Some(recent)); + return Ok(Some(StageB::from_cache(recent))); } let _slot = StageBSlot::acquire(db::setting_i64(db, "stage_b_concurrency", 1) as usize); let resolved = run(cfg, db, pb, recipe, recipe_hash, &tip_hash, stage_a)?; - db::stage_b_cache_put(db, pb.id, recipe_hash, &tip_hash, &resolved)?; + db::stage_b_cache_put(db, pb.id, recipe_hash, &tip_hash, &resolved.as_row())?; Ok(Some(resolved)) } |
