From 6a88707be1651f457df0960ec0ddc78dadf8ed3a Mon Sep 17 00:00:00 2001 From: Vika Date: Sat, 22 Jul 2023 12:21:11 +0300 Subject: postgres: optimize fetching of non-feeds by forgoing a second query --- kittybox-rs/src/database/postgres/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'kittybox-rs/src') diff --git a/kittybox-rs/src/database/postgres/mod.rs b/kittybox-rs/src/database/postgres/mod.rs index 41e4f58..b9a21c3 100644 --- a/kittybox-rs/src/database/postgres/mod.rs +++ b/kittybox-rs/src/database/postgres/mod.rs @@ -289,6 +289,15 @@ SELECT kittybox.hydrate_author(mf2) FROM kittybox.mf2_json WHERE uid = $1 None => return Ok(None) }; + // Don't query for children if this isn't a feed. + // + // The second query is very long and will probably be extremely + // expensive. It's best to skip it on types where it doesn't make sense + // (Kittybox doesn't support rendering children on non-feeds) + if !feed["type"].as_array().unwrap().iter().any(|t| *t == serde_json::json!("h-feed")) { + return Ok(Some((feed, None))); + } + feed["children"] = sqlx::query_scalar::<_, serde_json::Value>(" SELECT kittybox.hydrate_author(mf2) FROM kittybox.mf2_json INNER JOIN kittybox.children -- cgit 1.4.1