tangled
alpha
login
or
join now
parakeet.at
/
parakeet
64
fork
atom
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
64
fork
atom
overview
issues
12
pulls
pipelines
refactor(parakeet): move thread getters out for reuse
mia.omg.lol
5 months ago
e38a2ff5
b071e1f8
verified
This commit was signed with the committer's
known signature
.
mia.omg.lol
SSH Key Fingerprint:
SHA256:eb+NhC0QEl+XKRuFP/97oH6LEz0TXTKPXGDIAI5y7CQ=
+41
-25
2 changed files
expand all
collapse all
unified
split
parakeet
src
db.rs
xrpc
app_bsky
feed
posts.rs
+39
-1
parakeet/src/db.rs
···
1
1
use diesel::prelude::*;
2
2
-
use diesel::sql_types::{Array, Bool, Nullable, Text};
2
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
199
+
200
200
+
#[derive(Debug, QueryableByName)]
201
201
+
#[diesel(check_for_backend(diesel::pg::Pg))]
202
202
+
#[allow(unused)]
203
203
+
pub struct ThreadItem {
204
204
+
#[diesel(sql_type = Text)]
205
205
+
pub at_uri: String,
206
206
+
#[diesel(sql_type = Nullable<Text>)]
207
207
+
pub parent_uri: Option<String>,
208
208
+
#[diesel(sql_type = Nullable<Text>)]
209
209
+
pub root_uri: Option<String>,
210
210
+
#[diesel(sql_type = Integer)]
211
211
+
pub depth: i32,
212
212
+
}
213
213
+
214
214
+
pub async fn get_thread_children(
215
215
+
conn: &mut AsyncPgConnection,
216
216
+
uri: &str,
217
217
+
depth: i32,
218
218
+
) -> QueryResult<Vec<ThreadItem>> {
219
219
+
diesel::sql_query(include_str!("sql/thread.sql"))
220
220
+
.bind::<Text, _>(uri)
221
221
+
.bind::<Integer, _>(depth)
222
222
+
.load(conn)
223
223
+
.await
224
224
+
}
225
225
+
226
226
+
pub async fn get_thread_parents(
227
227
+
conn: &mut AsyncPgConnection,
228
228
+
uri: &str,
229
229
+
height: i32,
230
230
+
) -> QueryResult<Vec<ThreadItem>> {
231
231
+
diesel::sql_query(include_str!("sql/thread_parent.sql"))
232
232
+
.bind::<Text, _>(uri)
233
233
+
.bind::<Integer, _>(height)
234
234
+
.load(conn)
235
235
+
.await
236
236
+
}
+2
-24
parakeet/src/xrpc/app_bsky/feed/posts.rs
···
361
361
pub threadgate: Option<ThreadgateView>,
362
362
}
363
363
364
364
-
#[derive(Debug, QueryableByName)]
365
365
-
#[diesel(check_for_backend(diesel::pg::Pg))]
366
366
-
struct ThreadItem {
367
367
-
#[diesel(sql_type = diesel::sql_types::Text)]
368
368
-
at_uri: String,
369
369
-
#[diesel(sql_type = diesel::sql_types::Nullable<diesel::sql_types::Text>)]
370
370
-
parent_uri: Option<String>,
371
371
-
// #[diesel(sql_type = diesel::sql_types::Nullable<diesel::sql_types::Text>)]
372
372
-
// root_uri: Option<String>,
373
373
-
#[diesel(sql_type = diesel::sql_types::Integer)]
374
374
-
depth: i32,
375
375
-
}
376
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
412
-
let replies = diesel::sql_query(include_str!("../../../sql/thread.sql"))
413
413
-
.bind::<diesel::sql_types::Text, _>(&uri)
414
414
-
.bind::<diesel::sql_types::Integer, _>(depth as i32)
415
415
-
.load::<ThreadItem>(&mut conn)
416
416
-
.await?;
417
417
-
418
418
-
let parents = diesel::sql_query(include_str!("../../../sql/thread_parent.sql"))
419
419
-
.bind::<diesel::sql_types::Text, _>(&uri)
420
420
-
.bind::<diesel::sql_types::Integer, _>(parent_height as i32)
421
421
-
.load::<ThreadItem>(&mut conn)
422
422
-
.await?;
399
399
+
let replies = crate::db::get_thread_children(&mut conn, &uri, depth as i32).await?;
400
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();