Rust AppView - highly experimental!
1//! Database operations for batch writer workers 2//! 3//! These functions support the batch writer workers with bulk operations 4//! for actor ensuring. 5 6use super::Result; 7use deadpool_postgres::GenericClient; 8 9/// Bulk ensure actors exist in the database 10/// 11/// This function ensures all DIDs have actor entries by calling get_actor_id() for each, 12/// which uses advisory locks to prevent duplicate actor creation. 13/// 14/// Returns the number of new actor records created (existing actors are not counted). 15pub async fn bulk_ensure_actors<C: GenericClient>(conn: &C, dids: &[&str]) -> Result<u64> { 16 if dids.is_empty() { 17 return Ok(0); 18 } 19 20 let mut created_count = 0_u64; 21 22 // Loop through each DID and use get_actor_id() which has advisory lock protection 23 for did in dids { 24 let (_, _, was_created) = crate::db::operations::feed::get_actor_id(conn, did).await?; 25 if was_created { 26 created_count += 1; 27 } 28 } 29 30 Ok(created_count) 31} 32