~vikanezrimaya/kittybox

d5b7f7b180b487c01616763559fa38cbed8bb45e — Vika 1 year, 4 months ago cf9d3a4
postgres: Fix pretty permalinks not being shown
2 files changed, 22 insertions(+), 2 deletions(-)

M kittybox-rs/src/database/mod.rs
M kittybox-rs/src/database/postgres/mod.rs
M kittybox-rs/src/database/mod.rs => kittybox-rs/src/database/mod.rs +20 -0
@@ 717,6 717,25 @@ mod tests {
        assert_eq!(read_post["properties"]["comment"][0], reply);
    }

    async fn test_pretty_permalinks<Backend: Storage>(db: Backend) {
        const PERMALINK: &str = "https://fireburn.ru/posts/pretty-permalink";

        let post = {
            let mut post = gen_random_post("fireburn.ru");
            let urls = post["properties"]["url"].as_array_mut().unwrap();
            urls.push(serde_json::Value::String(
                PERMALINK.to_owned()
            ));

            post
        };
        db.put_post(&post, "fireburn.ru").await.unwrap();

        for i in post["properties"]["url"].as_array().unwrap() {
            let (read_post, _) = db.read_feed_with_cursor(i.as_str().unwrap(), None, 20, None).await.unwrap().unwrap();
            assert_eq!(read_post, post);
        }
    }
    /// Automatically generates a test suite for
    macro_rules! test_all {
        ($func_name:ident, $mod_name:ident) => {


@@ 727,6 746,7 @@ mod tests {
                $func_name!(test_update);
                $func_name!(test_feed_pagination);
                $func_name!(test_webmention_addition);
                $func_name!(test_pretty_permalinks);
            }
        };
    }

M kittybox-rs/src/database/postgres/mod.rs => kittybox-rs/src/database/postgres/mod.rs +2 -2
@@ 259,7 259,7 @@ SELECT jsonb_set(
    '{properties,author,0}',
    (SELECT mf2 FROM kittybox.mf2_json
     WHERE uid = mf2 #>> '{properties,author,0}')
) FROM kittybox.mf2_json WHERE uid = $1
) FROM kittybox.mf2_json WHERE uid = $1 OR mf2['properties']['url'] ? $1
")
            .bind(url)
            .fetch_optional(&self.db)


@@ 324,7 324,7 @@ ORDER BY mf2 #>> '{properties,published,0}' DESC
			.await?;
        tracing::debug!("Started txn: {:?}", txn);
        let mut feed = match sqlx::query_scalar::<_, serde_json::Value>("
SELECT kittybox.hydrate_author(mf2) FROM kittybox.mf2_json WHERE uid = $1
SELECT kittybox.hydrate_author(mf2) FROM kittybox.mf2_json WHERE uid = $1 OR mf2['properties']['url'] ? $1
")
            .bind(url)
            .fetch_optional(&mut *txn)