diff options
author | Vika <vika@fireburn.ru> | 2023-07-22 12:21:11 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2023-07-22 12:21:11 +0300 |
commit | 6a88707be1651f457df0960ec0ddc78dadf8ed3a (patch) | |
tree | cb589640c43ff23dae186d2a65661d66d4fb98f3 /kittybox-rs | |
parent | a87120c2fd537ca7ae92a2999984f16afebe5621 (diff) | |
download | kittybox-6a88707be1651f457df0960ec0ddc78dadf8ed3a.tar.zst |
postgres: optimize fetching of non-feeds by forgoing a second query
Diffstat (limited to 'kittybox-rs')
-rw-r--r-- | kittybox-rs/src/database/postgres/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
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 |