From 584eadfa6b9f96b23745a45fed48421c1694a267 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Mon, 15 Jan 2024 02:05:53 +0000 Subject: [PATCH] Fix fetch_latest_commit fetching the earliest commit --- src/database/schema/commit.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/database/schema/commit.rs b/src/database/schema/commit.rs index 5d9587d..7454113 100644 --- a/src/database/schema/commit.rs +++ a/src/database/schema/commit.rs @@ -188,19 +188,21 @@ } pub fn fetch_latest_one(&self) -> Result, anyhow::Error> { + let mut key = self.prefix.to_vec(); + key.extend_from_slice(&(self.len()? - 1).to_be_bytes()); + let cf = self .db .cf_handle(COMMIT_FAMILY) .context("missing column family")?; + + let Some(value) = self.db.get_cf(cf, key)? else { + return Ok(None); + }; - self.db - .prefix_iterator_cf(cf, &self.prefix) - .next() - .transpose() - .context("Failed to instantiate iterator")? - .map(|(_, value)| Yoke::try_attach_to_cart(value, |data| bincode::deserialize(data))) - .transpose() - .context("Failed to decode commit") + Yoke::try_attach_to_cart(Box::from(value), |data| bincode::deserialize(data)) + .map(Some) + .context("Failed to deserialize commit") } pub fn fetch_latest( -- rgit 0.1.3