Skip to content

Commit

Permalink
chore: improve /v1/publication/list_by_gids api.
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Sep 20, 2023
1 parent 43564bc commit 658b1ae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "writing"
version = "1.0.2"
version = "1.0.3"
edition = "2021"
rust-version = "1.64"
description = ""
Expand Down
8 changes: 5 additions & 3 deletions src/db/model_publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ impl Publication {
let secs: u32 = 3600 * 24;
let mut res: Vec<Publication> = Vec::new();
let query = format!(
"SELECT {} FROM publication WHERE gid=? AND status=? AND cid>=? AND cid<? USING TIMEOUT 3s",
"SELECT {} FROM publication WHERE gid=? AND status=? AND cid>=? AND cid<? LIMIT 1000 USING TIMEOUT 3s",
fields.clone().join(","));

let mut end_id = if let Some(cid) = page_token {
Expand All @@ -776,7 +776,7 @@ impl Publication {
};

let mut i = 0i8;
while i < 7 {
while i < 14 {
let raw = end_id.as_bytes();
let unix_ts = u32::from_be_bytes([raw[0], raw[1], raw[2], raw[3]]);
let mut start_id = xid::Id::default();
Expand Down Expand Up @@ -821,7 +821,9 @@ impl Publication {
end_id = start_id;
}

Ok((res, None))
let next = if res.is_empty() { None } else { Some(end_id) };
res.sort_by(|a, b| b.cid.partial_cmp(&a.cid).unwrap());
Ok((res, next))
}

pub async fn list_published_by_cid(
Expand Down

0 comments on commit 658b1ae

Please sign in to comment.