feat(web): pre-populate webfinger cache

when i put an actor in cache, put its pretty url in webfinger cache too
This commit is contained in:
əlemi 2024-07-05 17:17:26 +02:00
parent 59e71418ea
commit 29e9901583
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 15 additions and 4 deletions

View file

@ -19,7 +19,11 @@ pub fn ActorHeader() -> impl IntoView {
.await .await
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
let user = std::sync::Arc::new(user); let user = std::sync::Arc::new(user);
cache::OBJECTS.store(&Uri::full(U::Actor, &id), user.clone()); let uid = Uri::full(U::Actor, &id);
cache::OBJECTS.store(&uid, user.clone());
if let Some(url) = user.url().id().str() {
cache::WEBFINGER.store(&url, uid);
}
Ok(user) Ok(user)
}, },
} }

View file

@ -3,7 +3,7 @@ pub mod thread;
use std::{collections::BTreeSet, pin::Pin, sync::Arc}; use std::{collections::BTreeSet, pin::Pin, sync::Arc};
use apb::{field::OptionalString, Activity, ActivityMut, Base, Object}; use apb::{field::OptionalString, Activity, ActivityMut, Actor, Base, Object};
use leptos::*; use leptos::*;
use crate::prelude::*; use crate::prelude::*;
@ -169,9 +169,16 @@ async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth) -> V
} }
async fn fetch_and_update(kind: U, id: String, auth: Auth) { async fn fetch_and_update(kind: U, id: String, auth: Auth) {
match Http::fetch(&Uri::api(kind, &id, false), auth).await { match Http::fetch::<serde_json::Value>(&Uri::api(kind, &id, false), auth).await {
Ok(data) => { cache::OBJECTS.store(&id, Arc::new(data)); },
Err(e) => console_warn(&format!("could not fetch '{id}': {e}")), Err(e) => console_warn(&format!("could not fetch '{id}': {e}")),
Ok(data) => {
if data.actor_type().is_ok() {
if let Some(url) = data.url().id().str() {
cache::WEBFINGER.store(&id, url);
}
}
cache::OBJECTS.store(&id, Arc::new(data));
},
} }
} }