cob: Expose a lower-level loader for objects

The motivation here is to allow for caching.
This commit is contained in:
Lorenz Leutgeb
2026-11-02 21:50:08 +01:00
parent eee5cb8d8c
commit 795638dae0
2 changed files with 31 additions and 4 deletions
@@ -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;
@@ -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<T, S>(
storage: &S,
typename: &TypeName,
oid: &ObjectId,
objects: &Objects,
) -> Result<Option<CollaborativeObject<T>>, error::Retrieve>
where
T: Evaluate<S>,
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()
}