From 2e0bc349c3ff39c9cbfe0ca19d090cea971a7102 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..bf571ec 100644 --- a/src/database/schema/commit.rs +++ b/src/database/schema/commit.rs @@ -193,14 +193,16 @@ impl CommitTree { .cf_handle(COMMIT_FAMILY) .context("missing column family")?; - 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") + let mut key = self.prefix.to_vec(); + key.extend_from_slice(&self.len()?.to_be_bytes()); + + let Some(value) = self.db.get_cf(cf, key)? else { + return Ok(None); + }; + + Yoke::try_attach_to_cart(Box::from(value), |data| bincode::deserialize(data)) + .map(Some) + .context("Failed to deserialize commit") } pub fn fetch_latest(