Struct activitypub_federation::fetch::object_id::ObjectId
source · pub struct ObjectId<Kind>(/* private fields */)
where
Kind: Object,
for<'de2> <Kind as Object>::Kind: Deserialize<'de2>;
Expand description
Typed wrapper for Activitypub Object ID which helps with dereferencing and caching.
It provides convenient methods for fetching the object from remote server or local database. Objects are automatically cached locally, so they don’t have to be fetched every time. Much of the crate functionality relies on this wrapper.
Every time an object is fetched via HTTP, [RequestData.request_counter] is incremented by one. If the value exceeds [FederationSettings.http_fetch_limit], the request is aborted with Error::RequestLimit. This prevents denial of service attacks where an attack triggers infinite, recursive fetching of data.
let config = FederationConfig::builder()
.domain("example.com")
.app_data(db_connection)
.build().await?;
let request_data = config.to_request_data();
let object_id = ObjectId::<DbUser>::parse("https://lemmy.ml/u/nutomic")?;
// Attempt to fetch object from local database or fall back to remote server
let user = object_id.dereference(&request_data).await;
assert!(user.is_ok());
// Now you can also read the object from local database without network requests
let user = object_id.dereference_local(&request_data).await;
assert!(user.is_ok());
Implementations§
source§impl<Kind> ObjectId<Kind>
impl<Kind> ObjectId<Kind>
sourcepub fn parse(url: &str) -> Result<Self, ParseError>
pub fn parse(url: &str) -> Result<Self, ParseError>
Construct a new objectid instance
sourcepub fn into_inner(self) -> Url
pub fn into_inner(self) -> Url
Returns the wrapped URL value
sourcepub async fn dereference(
&self,
data: &Data<<Kind as Object>::DataType>
) -> Result<Kind, <Kind as Object>::Error>
pub async fn dereference( &self, data: &Data<<Kind as Object>::DataType> ) -> Result<Kind, <Kind as Object>::Error>
Fetches an activitypub object, either from local database (if possible), or over http.
sourcepub async fn dereference_forced(
&self,
data: &Data<<Kind as Object>::DataType>
) -> Result<Kind, <Kind as Object>::Error>
pub async fn dereference_forced( &self, data: &Data<<Kind as Object>::DataType> ) -> Result<Kind, <Kind as Object>::Error>
If this is a remote object, fetch it from origin instance unconditionally to get the latest version, regardless of refresh interval.
Trait Implementations§
source§impl<Kind> Clone for ObjectId<Kind>
impl<Kind> Clone for ObjectId<Kind>
Need to implement clone manually, to avoid requiring Kind to be Clone