//! Database operations for batch writer workers //! //! These functions support the batch writer workers with bulk operations //! for actor ensuring. use super::Result; use deadpool_postgres::GenericClient; /// Bulk ensure actors exist in the database /// /// This function ensures all DIDs have actor entries by calling get_actor_id() for each, /// which uses advisory locks to prevent duplicate actor creation. /// /// Returns the number of new actor records created (existing actors are not counted). pub async fn bulk_ensure_actors(conn: &C, dids: &[&str]) -> Result { if dids.is_empty() { return Ok(0); } let mut created_count = 0_u64; // Loop through each DID and use get_actor_id() which has advisory lock protection for did in dids { let (_, _, was_created) = crate::db::operations::feed::get_actor_id(conn, did).await?; if was_created { created_count += 1; } } Ok(created_count) }