From 43564bc8c0ba67d266a1c7ddd5a4954c64816b6b Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Wed, 20 Sep 2023 18:31:23 +0800 Subject: [PATCH] chore: improve /v1/publication/list_by_gids api. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/db/model_publication.rs | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0cb1be..223a53e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3025,7 +3025,7 @@ dependencies = [ [[package]] name = "writing" -version = "1.0.1" +version = "1.0.2" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 806be86..a894edf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "writing" -version = "1.0.1" +version = "1.0.2" edition = "2021" rust-version = "1.64" description = "" diff --git a/src/db/model_publication.rs b/src/db/model_publication.rs index e63e210..0c7bb94 100644 --- a/src/db/model_publication.rs +++ b/src/db/model_publication.rs @@ -776,7 +776,7 @@ impl Publication { }; let mut i = 0i8; - while i < 14 { + while i < 7 { 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(); @@ -810,7 +810,9 @@ impl Publication { } } - if !res.is_empty() { + // result should >= 6 for first page. + if (page_token.is_none() && res.len() >= 6) || (page_token.is_some() && res.len() >= 3) + { res.sort_by(|a, b| b.cid.partial_cmp(&a.cid).unwrap()); return Ok((res, Some(start_id))); }