Skip to main content

max / makenotwork

729 B · 30 lines History Blame Raw
1 //! link preview reads, batched over a post set rather than per post
2
3 use super::{PgPool, Uuid};
4
5 #[derive(sqlx::FromRow)]
6 pub struct LinkPreviewRow {
7 pub post_id: Uuid,
8 pub url: String,
9 pub title: Option<String>,
10 pub description: Option<String>,
11 }
12
13 /// Batch-fetch link previews for a set of post IDs.
14 #[tracing::instrument(skip_all)]
15 pub async fn list_link_previews_for_posts(
16 pool: &PgPool,
17 post_ids: &[Uuid],
18 ) -> Result<Vec<LinkPreviewRow>, sqlx::Error> {
19 sqlx::query_as!(
20 LinkPreviewRow,
21 "SELECT post_id, url, title, description
22 FROM link_previews
23 WHERE post_id = ANY($1)
24 ORDER BY fetched_at",
25 post_ids,
26 )
27 .fetch_all(pool)
28 .await
29 }
30