JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Re-expose Operation State in generics.

This is the worst code I have ever written. I hate the way this changes everything. ugh.

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨90db3e2

⁨giterated-cache/src/cache_update.rs⁩ - ⁨986⁩ bytes
Raw
1 use giterated_models::error::OperationError;
2 use giterated_stack::{AnyObject, AnyValue, GiteratedStack};
3 use tracing::trace;
4
5 use crate::{CacheKey, CacheSubstack};
6
7 pub async fn cache_updated(
8 object: AnyObject,
9 value: AnyValue,
10 state: CacheSubstack,
11 stack: GiteratedStack,
12 ) -> Result<(), OperationError<anyhow::Error>> {
13 let object_meta = stack
14 .metadata
15 .objects
16 .get(object.kind())
17 .ok_or_else(|| OperationError::Unhandled)?;
18 let object_str = (object_meta.to_str)(object.clone());
19 let cache_key = CacheKey {
20 object: object_str,
21 value_name: value.kind().value_kind.to_string(),
22 };
23
24 let value_kind = value.kind().value_kind;
25 trace!(
26 "Beginning cache update for {}::{}",
27 object.kind(),
28 value_kind
29 );
30
31 state.cache.insert(cache_key, value).await;
32
33 trace!(
34 "Completed cache update for {}::{}",
35 object.kind(),
36 value_kind
37 );
38 Ok(())
39 }
40