diff options
author | Vika <vika@fireburn.ru> | 2023-06-22 20:28:21 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2023-06-22 20:28:21 +0300 |
commit | d61e1f6a8e5ad5b7c14b1f9ab3101496f3f9ea00 (patch) | |
tree | a8db5c905061fd25b19825a4d8aee890dd7c62b2 /kittybox-rs/src/frontend | |
parent | ff358723da641af9f4ae1f742eb1b382f4630220 (diff) | |
download | kittybox-d61e1f6a8e5ad5b7c14b1f9ab3101496f3f9ea00.tar.zst |
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.
Diffstat (limited to 'kittybox-rs/src/frontend')
-rw-r--r-- | kittybox-rs/src/frontend/mod.rs | 13 |
1 files changed, 7 insertions, 6 deletions
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<S: Storage>( url: &str, after: Option<String>, user: &Option<String>, -) -> std::result::Result<serde_json::Value, FrontendError> { +) -> std::result::Result<(serde_json::Value, Option<String>), 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<D: Storage>( 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<D: Storage>( 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<D: Storage>( .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::<crate::database::settings::SiteName>(&host) .map(Result::unwrap_or_default), @@ -240,7 +241,7 @@ pub async fn catchall<D: Storage>( 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) |