Skip to main content

max / makenotwork

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