From d61e1f6a8e5ad5b7c14b1f9ab3101496f3f9ea00 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 22 Jun 2023 20:28:21 +0300 Subject: database: introduce read_feed_with_cursor read_feed_with_cursor allows using an arbitrary string as a cursor, unlike read_feed_with_limit, which uses last post's UID as a cursor. --- kittybox-rs/src/frontend/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'kittybox-rs/src/frontend') diff --git a/kittybox-rs/src/frontend/mod.rs b/kittybox-rs/src/frontend/mod.rs index b90d57c..d677005 100644 --- a/kittybox-rs/src/frontend/mod.rs +++ b/kittybox-rs/src/frontend/mod.rs @@ -79,13 +79,13 @@ async fn get_post_from_database( url: &str, after: Option, user: &Option, -) -> std::result::Result { +) -> std::result::Result<(serde_json::Value, Option), FrontendError> { match db - .read_feed_with_limit(url, &after, POSTS_PER_PAGE, user) + .read_feed_with_cursor(url, after.as_deref(), POSTS_PER_PAGE, user.as_deref()) .await { Ok(result) => match result { - Some(post) => Ok(post), + Some((post, cursor)) => Ok((post, cursor)), None => Err(FrontendError::with_code( StatusCode::NOT_FOUND, "Post not found in the database", @@ -125,7 +125,7 @@ pub async fn homepage( get_post_from_database(&db, &path, None, &user), get_post_from_database(&db, &feed_path, query.after, &user) ) { - Ok((hcard, hfeed)) => { + Ok(((hcard, _), (hfeed, cursor))) => { // Here, we know those operations can't really fail // (or it'll be a transient failure that will show up on // other requests anyway if it's serious...) @@ -155,6 +155,7 @@ pub async fn homepage( content: MainPage { feed: &hfeed, card: &hcard, + cursor: cursor.as_deref(), webring: crate::database::settings::Setting::into_inner(webring) } .to_string(), @@ -219,7 +220,7 @@ pub async fn catchall( .unwrap(); match get_post_from_database(&db, path.as_str(), query.after, &user).await { - Ok(post) => { + Ok((post, cursor)) => { let (blogname, channels) = tokio::join!( db.get_setting::(&host) .map(Result::unwrap_or_default), @@ -240,7 +241,7 @@ pub async fn catchall( user, content: match post.pointer("/type/0").and_then(|i| i.as_str()) { Some("h-entry") => Entry { post: &post }.to_string(), - Some("h-feed") => Feed { feed: &post }.to_string(), + Some("h-feed") => Feed { feed: &post, cursor: cursor.as_deref() }.to_string(), Some("h-card") => VCard { card: &post }.to_string(), unknown => { unimplemented!("Template for MF2-JSON type {:?}", unknown) -- cgit 1.4.1