From 795638dae089eff750c14e8238bf2a43d18ef15b Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 2 Nov 2026 21:08:51 +0100 Subject: [PATCH] cob: Expose a lower-level loader for objects The motivation here is to allow for caching. --- .../radicle-cob/src/object/collaboration.rs | 2 +- .../src/object/collaboration/get.rs | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/crates/radicle-cob/src/object/collaboration.rs b/crates/radicle-cob/src/object/collaboration.rs index 90f23017a..9f2119c76 100644 --- a/crates/radicle-cob/src/object/collaboration.rs +++ b/crates/radicle-cob/src/object/collaboration.rs @@ -14,7 +14,7 @@ mod create; pub use create::{Create, create}; mod get; -pub use get::get; +pub use get::{get, get_from_objects}; pub mod info; diff --git a/crates/radicle-cob/src/object/collaboration/get.rs b/crates/radicle-cob/src/object/collaboration/get.rs index 235a950d5..b6c9c3648 100644 --- a/crates/radicle-cob/src/object/collaboration/get.rs +++ b/crates/radicle-cob/src/object/collaboration/get.rs @@ -1,6 +1,8 @@ // Copyright © 2022 The Radicle Link Contributors -use crate::{CollaborativeObject, Evaluate, ObjectId, TypeName, change_graph::ChangeGraph}; +use crate::{ + CollaborativeObject, Evaluate, ObjectId, TypeName, change_graph::ChangeGraph, object::Objects, +}; use super::error; @@ -28,11 +30,36 @@ where Signature = crypto::Signature, >, { - let tip_refs = storage + let objects = storage .objects(typename, oid) .map_err(|err| error::Retrieve::Refs { err: Box::new(err) })?; - ChangeGraph::load(storage, tip_refs.iter(), typename, oid) + get_from_objects(storage, typename, oid, &objects) +} + +/// Get a [`CollaborativeObject`] from given `objects`. +/// +/// The corresponding higher-level function is [`get`], which will resolve +/// `objects` from storage. +/// +/// This function is useful for callers that want to avoid re-reading +/// references from storage. +pub fn get_from_objects( + storage: &S, + typename: &TypeName, + oid: &ObjectId, + objects: &Objects, +) -> Result>, error::Retrieve> +where + T: Evaluate, + S: crate::change::Storage< + ObjectId = crate::object::Oid, + Parent = crate::object::Oid, + PublicKey = crypto::PublicKey, + Signature = crypto::Signature, + >, +{ + ChangeGraph::load(storage, objects.iter(), typename, oid) .map(|graph| graph.evaluate(storage).map_err(error::Retrieve::evaluate)) .transpose() }