Skip to content

Commit

Permalink
Merge pull request #530 from thoth-pub/feature/fix_query_pagination
Browse files Browse the repository at this point in the history
Fix pagination offset calculation
  • Loading branch information
ja573 authored Dec 20, 2023
2 parents 973c076 + b6538d9 commit 0f14386
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- [530](https://github.com/thoth-pub/thoth/pull/530) - Fix pagination offset calculation in export API
- [530](https://github.com/thoth-pub/thoth/pull/530) - Do not allow to create more than one price in the same currency for the same publication

## [[0.11.11]](https://github.com/thoth-pub/thoth/releases/tag/v0.11.11) - 2023-12-19
### Changed
Expand Down
1 change: 1 addition & 0 deletions thoth-api/migrations/v0.11.12/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE price DROP CONSTRAINT price_publication_id_currency_code_uniq;
2 changes: 2 additions & 0 deletions thoth-api/migrations/v0.11.12/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE price ADD CONSTRAINT price_publication_id_currency_code_uniq
UNIQUE (publication_id, currency_code);
1 change: 1 addition & 0 deletions thoth-errors/src/database_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static DATABASE_CONSTRAINT_ERRORS: Map<&'static str, &'static str> = phf_map! {
"location_uniq_platform_idx" => "A location on the selected platform already exists.",
"location_url_check" => "A location must have a landing page and/or a full text URL.",
"orcid_uniq_idx" => "A contributor with this ORCID ID already exists.",
"price_publication_id_currency_code_uniq" => "A price in this currency already exists for this publication.",
"price_unit_price_check" => "Price values must be greater than zero. To indicate an unpriced Publication, omit all Prices.",
"publication_depth_in_check" => "Publication depth must be greater than 0.0.",
"publication_depth_in_not_missing" => "When specifying Depth, both values (mm and in) must be supplied.",
Expand Down
12 changes: 5 additions & 7 deletions thoth-export-server/src/specification_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ impl SpecificationQuery {
.thoth_client
.get_work_count(Some(vec![publisher_id]))
.await?;
let total_pages = (work_count / PAGINATION_LIMIT) + 1;
// calculate total pages, rounding up to ensure all works are covered
let total_pages = (work_count + PAGINATION_LIMIT - 1) / PAGINATION_LIMIT;
// get a vector of all page offsets we will need
let offsets = match total_pages {
1 => vec![0], // otherwise a range of (1..1) gives us nothing
_ => (1..total_pages)
.map(|current_page| (current_page - 1) * PAGINATION_LIMIT)
.collect::<Vec<i64>>(),
};
let offsets = (1..=total_pages) // inclusive upper bound
.map(|current_page| (current_page - 1) * PAGINATION_LIMIT)
.collect::<Vec<i64>>();

// make concurrent requests iterating the list of offsets to asynchronously obtain all pages
let mut works_pages = stream::iter(offsets)
Expand Down

0 comments on commit 0f14386

Please sign in to comment.