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.

refactor(parakeet): move thread getters out for reuse

authored by

Mia and committed by
Tangled
8f126b02 0866650f

+41 -25
+39 -1
parakeet/src/db.rs
··· 1 1 use diesel::prelude::*; 2 - use diesel::sql_types::{Array, Bool, Nullable, Text}; 2 + use diesel::sql_types::{Array, Bool, Integer, Nullable, Text}; 3 3 use diesel_async::{AsyncPgConnection, RunQueryDsl}; 4 4 use parakeet_db::{schema, types}; 5 5 ··· 196 196 .await 197 197 .optional() 198 198 } 199 + 200 + #[derive(Debug, QueryableByName)] 201 + #[diesel(check_for_backend(diesel::pg::Pg))] 202 + #[allow(unused)] 203 + pub struct ThreadItem { 204 + #[diesel(sql_type = Text)] 205 + pub at_uri: String, 206 + #[diesel(sql_type = Nullable<Text>)] 207 + pub parent_uri: Option<String>, 208 + #[diesel(sql_type = Nullable<Text>)] 209 + pub root_uri: Option<String>, 210 + #[diesel(sql_type = Integer)] 211 + pub depth: i32, 212 + } 213 + 214 + pub async fn get_thread_children( 215 + conn: &mut AsyncPgConnection, 216 + uri: &str, 217 + depth: i32, 218 + ) -> QueryResult<Vec<ThreadItem>> { 219 + diesel::sql_query(include_str!("sql/thread.sql")) 220 + .bind::<Text, _>(uri) 221 + .bind::<Integer, _>(depth) 222 + .load(conn) 223 + .await 224 + } 225 + 226 + pub async fn get_thread_parents( 227 + conn: &mut AsyncPgConnection, 228 + uri: &str, 229 + height: i32, 230 + ) -> QueryResult<Vec<ThreadItem>> { 231 + diesel::sql_query(include_str!("sql/thread_parent.sql")) 232 + .bind::<Text, _>(uri) 233 + .bind::<Integer, _>(height) 234 + .load(conn) 235 + .await 236 + }
+2 -24
parakeet/src/xrpc/app_bsky/feed/posts.rs
··· 361 361 pub threadgate: Option<ThreadgateView>, 362 362 } 363 363 364 - #[derive(Debug, QueryableByName)] 365 - #[diesel(check_for_backend(diesel::pg::Pg))] 366 - struct ThreadItem { 367 - #[diesel(sql_type = diesel::sql_types::Text)] 368 - at_uri: String, 369 - #[diesel(sql_type = diesel::sql_types::Nullable<diesel::sql_types::Text>)] 370 - parent_uri: Option<String>, 371 - // #[diesel(sql_type = diesel::sql_types::Nullable<diesel::sql_types::Text>)] 372 - // root_uri: Option<String>, 373 - #[diesel(sql_type = diesel::sql_types::Integer)] 374 - depth: i32, 375 - } 376 - 377 364 pub async fn get_post_thread( 378 365 State(state): State<GlobalState>, 379 366 AtpAcceptLabelers(labelers): AtpAcceptLabelers, ··· 409 396 } 410 397 } 411 398 412 - let replies = diesel::sql_query(include_str!("../../../sql/thread.sql")) 413 - .bind::<diesel::sql_types::Text, _>(&uri) 414 - .bind::<diesel::sql_types::Integer, _>(depth as i32) 415 - .load::<ThreadItem>(&mut conn) 416 - .await?; 417 - 418 - let parents = diesel::sql_query(include_str!("../../../sql/thread_parent.sql")) 419 - .bind::<diesel::sql_types::Text, _>(&uri) 420 - .bind::<diesel::sql_types::Integer, _>(parent_height as i32) 421 - .load::<ThreadItem>(&mut conn) 422 - .await?; 399 + let replies = crate::db::get_thread_children(&mut conn, &uri, depth as i32).await?; 400 + let parents = crate::db::get_thread_parents(&mut conn, &uri, parent_height as i32).await?; 423 401 424 402 let reply_uris = replies.iter().map(|item| item.at_uri.clone()).collect(); 425 403 let parent_uris = parents.iter().map(|item| item.at_uri.clone()).collect();