diff --git a/src/post_listener.rs b/src/post_listener.rs index 80f2a07..fb41bc2 100644 --- a/src/post_listener.rs +++ b/src/post_listener.rs @@ -98,26 +98,23 @@ pub async fn websocket_listener(pool: sqlx::Pool) { .collect::>(); for (rkey, uri) in features { - let uri_parts: Vec<&str> = uri.split_terminator('/').collect(); - if let Some(&slug) = uri_parts.last() { - let time_us_string = info.time_us.to_string(); - let time_us = &time_us_string; + let Some(slug) = uri.split_terminator('/').next_back() else { + log::error!("[jetstream] Failed to extract slug from URI: {}", uri); + continue; + }; + + let time_us = info.time_us.to_string(); - match sqlx::query("INSERT INTO posts (slug, rkey, time_us) VALUES ($1, $2, $3) ON CONFLICT (slug) DO NOTHING") - .bind(slug) - .bind(rkey) - .bind(time_us) - .execute(&pool) - .await { - Ok(_) => { - log::info!("[jetstream] Inserted post"); - } - Err(e) => { - log::error!("[jetstream] Failed to insert post: {}", e); - } - } + if let Err(e) = sqlx::query("INSERT INTO posts (slug, rkey, time_us) VALUES ($1, $2, $3) ON CONFLICT (slug) DO NOTHING") + .bind(slug) + .bind(&rkey) + .bind(&time_us) + .execute(&pool) + .await + { + log::error!("[jetstream] Failed to insert post: {}", e); } else { - log::error!("[jetstream] Failed to extract slug from URI: {}", uri); + log::info!("[jetstream] Inserted post"); } } }