1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-05-08 22:26:04 +02:00

Rework paging

The "totalPages" value in our response is calculated incorrectly.
Instead of casting to int and rounding, we should rather round up
to the next integer with math.ceil. This is a more correct way to
get the value.

Also update the indexer to use the same logic, although there the
values are printed with +1 so they are more readable.
This commit is contained in:
2020-12-27 12:22:07 +02:00
parent a02211fd60
commit 4f8cd1097b
2 changed files with 8 additions and 6 deletions

View File

@ -28,6 +28,8 @@
#
# See: https://wiki.duraspace.org/display/DSPACE/Solr
import math
import psycopg2.extras
import requests
@ -75,9 +77,9 @@ def index_views(indexType: str, facetField: str):
exit(0)
# divide results into "pages" (cast to int to effectively round down)
# divide results into "pages" and round up to next integer
results_per_page = 100
results_num_pages = int(results_totalNumFacets / results_per_page)
results_num_pages = math.ceil(results_totalNumFacets / results_per_page)
results_current_page = 0
with DatabaseManager() as db:
@ -158,9 +160,8 @@ def index_downloads(indexType: str, facetField: str):
exit(0)
# divide results into "pages" (cast to int to effectively round down)
results_per_page = 100
results_num_pages = int(results_totalNumFacets / results_per_page)
results_num_pages = math.ceil(results_totalNumFacets / results_per_page)
results_current_page = 0
with DatabaseManager() as db: