Parakeet is a Rust-based Bluesky AppServer aiming to implement most of the functionality required to support the Bluesky client
appview atproto bluesky rust appserver
66
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(parakeet): tidy up the profile hydrator a bit

Mia e00e955f 80baef1e

+30 -65
+29 -64
parakeet/src/hydration/profile.rs
··· 1 1 use crate::hydration::map_labels; 2 + use crate::loaders::ProfileLoaderRet; 2 3 use chrono::prelude::*; 4 + use chrono::TimeDelta; 3 5 use lexica::app_bsky::actor::*; 4 6 use lexica::app_bsky::embed::External; 5 7 use parakeet_db::models; ··· 7 9 use std::collections::HashMap; 8 10 use std::str::FromStr; 9 11 use std::sync::OnceLock; 10 - use chrono::TimeDelta; 11 12 12 13 pub static TRUSTED_VERIFIERS: OnceLock<Vec<String>> = OnceLock::new(); 13 14 ··· 146 147 } 147 148 148 149 fn build_basic( 149 - handle: Option<String>, 150 - profile: models::Profile, 151 - chat_decl: Option<ChatAllowIncoming>, 152 - is_labeler: bool, 150 + (handle, profile, chat_decl, is_labeler, stats, status): ProfileLoaderRet, 153 151 labels: Vec<models::Label>, 154 152 verifications: Option<Vec<models::VerificationEntry>>, 155 - stats: Option<ProfileStats>, 156 - status: Option<models::Status>, 157 153 ) -> ProfileViewBasic { 158 154 let associated = build_associated(chat_decl, is_labeler, stats); 159 155 let verification = build_verification(&profile, &handle, verifications); ··· 175 171 } 176 172 177 173 fn build_profile( 178 - handle: Option<String>, 179 - profile: models::Profile, 180 - chat_decl: Option<ChatAllowIncoming>, 181 - is_labeler: bool, 174 + (handle, profile, chat_decl, is_labeler, stats, status): ProfileLoaderRet, 182 175 labels: Vec<models::Label>, 183 176 verifications: Option<Vec<models::VerificationEntry>>, 184 - stats: Option<ProfileStats>, 185 - status: Option<models::Status>, 186 177 ) -> ProfileView { 187 178 let associated = build_associated(chat_decl, is_labeler, stats); 188 179 let verification = build_verification(&profile, &handle, verifications); ··· 206 197 } 207 198 208 199 fn build_detailed( 209 - handle: Option<String>, 210 - profile: models::Profile, 211 - chat_decl: Option<ChatAllowIncoming>, 212 - is_labeler: bool, 200 + (handle, profile, chat_decl, is_labeler, stats, status): ProfileLoaderRet, 213 201 labels: Vec<models::Label>, 214 202 verifications: Option<Vec<models::VerificationEntry>>, 215 - stats: Option<ProfileStats>, 216 - status: Option<models::Status>, 217 203 ) -> ProfileViewDetailed { 218 204 let associated = build_associated(chat_decl, is_labeler, stats); 219 205 let verification = build_verification(&profile, &handle, verifications); ··· 245 231 pub async fn hydrate_profile_basic(&self, did: String) -> Option<ProfileViewBasic> { 246 232 let labels = self.get_profile_label(&did).await; 247 233 let verif = self.loaders.verification.load(did.clone()).await; 248 - let (handle, profile, chat_decl, labeler, stats, status) = 249 - self.loaders.profile.load(did).await?; 234 + let profile_info = self.loaders.profile.load(did).await?; 250 235 251 - Some(build_basic( 252 - handle, profile, chat_decl, labeler, labels, verif, stats, status, 253 - )) 236 + Some(build_basic(profile_info, labels, verif)) 254 237 } 255 238 256 239 pub async fn hydrate_profiles_basic( ··· 263 246 264 247 profiles 265 248 .into_iter() 266 - .map( 267 - |(k, (handle, profile, chat_decl, labeler, stats, status))| { 268 - let labels = labels.get(&k).cloned().unwrap_or_default(); 269 - let verif = verif.get(&k).cloned(); 249 + .map(|(k, profile_info)| { 250 + let labels = labels.get(&k).cloned().unwrap_or_default(); 251 + let verif = verif.get(&k).cloned(); 270 252 271 - let v = build_basic( 272 - handle, profile, chat_decl, labeler, labels, verif, stats, status, 273 - ); 274 - (k, v) 275 - }, 276 - ) 253 + let v = build_basic(profile_info, labels, verif); 254 + (k, v) 255 + }) 277 256 .collect() 278 257 } 279 258 ··· 281 260 let labels = self.get_profile_label(&did).await; 282 261 283 262 let verif = self.loaders.verification.load(did.clone()).await; 284 - let (handle, profile, chat_decl, labeler, stats, status) = 285 - self.loaders.profile.load(did).await?; 263 + let profile_info = self.loaders.profile.load(did).await?; 286 264 287 - Some(build_profile( 288 - handle, profile, chat_decl, labeler, labels, verif, stats, status, 289 - )) 265 + Some(build_profile(profile_info, labels, verif)) 290 266 } 291 267 292 268 pub async fn hydrate_profiles(&self, dids: Vec<String>) -> HashMap<String, ProfileView> { ··· 296 272 297 273 profiles 298 274 .into_iter() 299 - .map( 300 - |(k, (handle, profile, chat_decl, labeler, stats, status))| { 301 - let labels = labels.get(&k).cloned().unwrap_or_default(); 302 - let verif = verif.get(&k).cloned(); 275 + .map(|(k, profile_info)| { 276 + let labels = labels.get(&k).cloned().unwrap_or_default(); 277 + let verif = verif.get(&k).cloned(); 303 278 304 - let v = build_profile( 305 - handle, profile, chat_decl, labeler, labels, verif, stats, status, 306 - ); 307 - (k, v) 308 - }, 309 - ) 279 + let v = build_profile(profile_info, labels, verif); 280 + (k, v) 281 + }) 310 282 .collect() 311 283 } 312 284 ··· 314 286 let labels = self.get_profile_label(&did).await; 315 287 316 288 let verif = self.loaders.verification.load(did.clone()).await; 317 - let (handle, profile, chat_decl, labeler, stats, status) = 318 - self.loaders.profile.load(did).await?; 289 + let profile_info = self.loaders.profile.load(did).await?; 319 290 320 - Some(build_detailed( 321 - handle, profile, chat_decl, labeler, labels, verif, stats, status, 322 - )) 291 + Some(build_detailed(profile_info, labels, verif)) 323 292 } 324 293 325 294 pub async fn hydrate_profiles_detailed( ··· 332 301 333 302 profiles 334 303 .into_iter() 335 - .map( 336 - |(k, (handle, profile, chat_decl, labeler, stats, status))| { 337 - let labels = labels.get(&k).cloned().unwrap_or_default(); 338 - let verif = verif.get(&k).cloned(); 304 + .map(|(k, profile_info)| { 305 + let labels = labels.get(&k).cloned().unwrap_or_default(); 306 + let verif = verif.get(&k).cloned(); 339 307 340 - let v = build_detailed( 341 - handle, profile, chat_decl, labeler, labels, verif, stats, status, 342 - ); 343 - (k, v) 344 - }, 345 - ) 308 + let v = build_detailed(profile_info, labels, verif); 309 + (k, v) 310 + }) 346 311 .collect() 347 312 } 348 313 }
+1 -1
parakeet/src/loaders.rs
··· 67 67 } 68 68 69 69 pub struct ProfileLoader(Pool<AsyncPgConnection>, parakeet_index::Client); 70 - type ProfileLoaderRet = ( 70 + pub type ProfileLoaderRet = ( 71 71 Option<String>, 72 72 models::Profile, 73 73 Option<ChatAllowIncoming>,