From e00e955f3690feaa43105d1fa4917ddacfa6a9c1 Mon Sep 17 00:00:00 2001 From: Mia Date: Sat, 21 Jun 2025 15:54:40 +0100 Subject: [PATCH] fix(parakeet): tidy up the profile hydrator a bit --- parakeet/src/hydration/profile.rs | 99 ++++++++++--------------------- parakeet/src/loaders.rs | 2 +- 2 files changed, 33 insertions(+), 68 deletions(-) diff --git a/parakeet/src/hydration/profile.rs b/parakeet/src/hydration/profile.rs index 7f6cabb8..d4133e02 100644 --- a/parakeet/src/hydration/profile.rs +++ b/parakeet/src/hydration/profile.rs @@ -1,5 +1,7 @@ use crate::hydration::map_labels; +use crate::loaders::ProfileLoaderRet; use chrono::prelude::*; +use chrono::TimeDelta; use lexica::app_bsky::actor::*; use lexica::app_bsky::embed::External; use parakeet_db::models; @@ -7,7 +9,6 @@ use parakeet_index::ProfileStats; use std::collections::HashMap; use std::str::FromStr; use std::sync::OnceLock; -use chrono::TimeDelta; pub static TRUSTED_VERIFIERS: OnceLock> = OnceLock::new(); @@ -146,14 +147,9 @@ fn build_status(status: models::Status) -> Option { } fn build_basic( - handle: Option, - profile: models::Profile, - chat_decl: Option, - is_labeler: bool, + (handle, profile, chat_decl, is_labeler, stats, status): ProfileLoaderRet, labels: Vec, verifications: Option>, - stats: Option, - status: Option, ) -> ProfileViewBasic { let associated = build_associated(chat_decl, is_labeler, stats); let verification = build_verification(&profile, &handle, verifications); @@ -175,14 +171,9 @@ fn build_basic( } fn build_profile( - handle: Option, - profile: models::Profile, - chat_decl: Option, - is_labeler: bool, + (handle, profile, chat_decl, is_labeler, stats, status): ProfileLoaderRet, labels: Vec, verifications: Option>, - stats: Option, - status: Option, ) -> ProfileView { let associated = build_associated(chat_decl, is_labeler, stats); let verification = build_verification(&profile, &handle, verifications); @@ -206,14 +197,9 @@ fn build_profile( } fn build_detailed( - handle: Option, - profile: models::Profile, - chat_decl: Option, - is_labeler: bool, + (handle, profile, chat_decl, is_labeler, stats, status): ProfileLoaderRet, labels: Vec, verifications: Option>, - stats: Option, - status: Option, ) -> ProfileViewDetailed { let associated = build_associated(chat_decl, is_labeler, stats); let verification = build_verification(&profile, &handle, verifications); @@ -245,12 +231,9 @@ impl super::StatefulHydrator<'_> { pub async fn hydrate_profile_basic(&self, did: String) -> Option { let labels = self.get_profile_label(&did).await; let verif = self.loaders.verification.load(did.clone()).await; - let (handle, profile, chat_decl, labeler, stats, status) = - self.loaders.profile.load(did).await?; + let profile_info = self.loaders.profile.load(did).await?; - Some(build_basic( - handle, profile, chat_decl, labeler, labels, verif, stats, status, - )) + Some(build_basic(profile_info, labels, verif)) } pub async fn hydrate_profiles_basic( @@ -263,17 +246,13 @@ impl super::StatefulHydrator<'_> { profiles .into_iter() - .map( - |(k, (handle, profile, chat_decl, labeler, stats, status))| { - let labels = labels.get(&k).cloned().unwrap_or_default(); - let verif = verif.get(&k).cloned(); - - let v = build_basic( - handle, profile, chat_decl, labeler, labels, verif, stats, status, - ); - (k, v) - }, - ) + .map(|(k, profile_info)| { + let labels = labels.get(&k).cloned().unwrap_or_default(); + let verif = verif.get(&k).cloned(); + + let v = build_basic(profile_info, labels, verif); + (k, v) + }) .collect() } @@ -281,12 +260,9 @@ impl super::StatefulHydrator<'_> { let labels = self.get_profile_label(&did).await; let verif = self.loaders.verification.load(did.clone()).await; - let (handle, profile, chat_decl, labeler, stats, status) = - self.loaders.profile.load(did).await?; + let profile_info = self.loaders.profile.load(did).await?; - Some(build_profile( - handle, profile, chat_decl, labeler, labels, verif, stats, status, - )) + Some(build_profile(profile_info, labels, verif)) } pub async fn hydrate_profiles(&self, dids: Vec) -> HashMap { @@ -296,17 +272,13 @@ impl super::StatefulHydrator<'_> { profiles .into_iter() - .map( - |(k, (handle, profile, chat_decl, labeler, stats, status))| { - let labels = labels.get(&k).cloned().unwrap_or_default(); - let verif = verif.get(&k).cloned(); - - let v = build_profile( - handle, profile, chat_decl, labeler, labels, verif, stats, status, - ); - (k, v) - }, - ) + .map(|(k, profile_info)| { + let labels = labels.get(&k).cloned().unwrap_or_default(); + let verif = verif.get(&k).cloned(); + + let v = build_profile(profile_info, labels, verif); + (k, v) + }) .collect() } @@ -314,12 +286,9 @@ impl super::StatefulHydrator<'_> { let labels = self.get_profile_label(&did).await; let verif = self.loaders.verification.load(did.clone()).await; - let (handle, profile, chat_decl, labeler, stats, status) = - self.loaders.profile.load(did).await?; + let profile_info = self.loaders.profile.load(did).await?; - Some(build_detailed( - handle, profile, chat_decl, labeler, labels, verif, stats, status, - )) + Some(build_detailed(profile_info, labels, verif)) } pub async fn hydrate_profiles_detailed( @@ -332,17 +301,13 @@ impl super::StatefulHydrator<'_> { profiles .into_iter() - .map( - |(k, (handle, profile, chat_decl, labeler, stats, status))| { - let labels = labels.get(&k).cloned().unwrap_or_default(); - let verif = verif.get(&k).cloned(); - - let v = build_detailed( - handle, profile, chat_decl, labeler, labels, verif, stats, status, - ); - (k, v) - }, - ) + .map(|(k, profile_info)| { + let labels = labels.get(&k).cloned().unwrap_or_default(); + let verif = verif.get(&k).cloned(); + + let v = build_detailed(profile_info, labels, verif); + (k, v) + }) .collect() } } diff --git a/parakeet/src/loaders.rs b/parakeet/src/loaders.rs index 47df34b2..73cb067e 100644 --- a/parakeet/src/loaders.rs +++ b/parakeet/src/loaders.rs @@ -67,7 +67,7 @@ impl BatchFn for HandleLoader { } pub struct ProfileLoader(Pool, parakeet_index::Client); -type ProfileLoaderRet = ( +pub type ProfileLoaderRet = ( Option, models::Profile, Option, -- 2.51.2