Skip to content

Commit

Permalink
Simplify record pagination
Browse files Browse the repository at this point in the history
Using simpler method should avoid unneccessary
extra api requests.
  • Loading branch information
wkmor1 committed Oct 27, 2023
1 parent 44dd828 commit dbd62ed
Show file tree
Hide file tree
Showing 5 changed files with 4,021 additions and 88 deletions.
18 changes: 5 additions & 13 deletions R/finbif_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -887,23 +887,15 @@ get_extra_pages <- function(fb_records_list) {

}

if (page > n_pages) {
if (page == n_pages + 1) {

last_record <- page_size * n_pages
page_size <- n %% page_size

if (identical(last_record, n)) {

break

}

page_size <- get_next_lowest_factor(last_record, n %% page_size)

page <- last_record / page_size
}

page <- page + 1L
if (page == n_pages + 2 || page_size == 0) {

n_pages <- n %/% page_size
break

}

Expand Down
23 changes: 0 additions & 23 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@

#' @noRd

get_next_lowest_factor <- function(
x,
y
) {

x <- as.integer(x)

y <- as.integer(y)

if (identical(x %% y, 0L)) {

return(y)

}

y <- y - 1L

get_next_lowest_factor(x, y)

}

#' @noRd

get_el_recurse <- function(
obj,
nms,
Expand Down
35 changes: 34 additions & 1 deletion tests/cassettes/finbif_get_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,38 @@ http_interactions:
encoding: ''
file: no
string: '{"currentPage":1,"lastPage":1,"pageSize":1000,"total":2,"results":[{"unit":{"unitId":"http://mus.utu.fi/MY.2475121"}},{"unit":{"unitId":"http://mus.utu.fi/MY.2475184"}}]}'
recorded_at: 2023-09-28 13:16:10 GMT
recorded_at: 2023-10-26 05:29:07 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
- request:
method: get
uri: https://apitest.laji.fi/v0/warehouse/query/unit/list?collectionId=HR.778&selected=unit.unitId&page=1&pageSize=100&access_token=<finbif_token>
body:
encoding: ''
string: ''
headers:
Content-Type: ''
Accept: application/json
response:
status:
status_code: 200
category: Success
reason: OK
message: 'Success: (200) OK'
headers:
date: Thu, 26 Oct 2023 05:29:06 GMT
content-type: application/json;charset=utf-8
transfer-encoding: chunked
access-control-allow-origin: '*'
via: 1.0 staging.laji.fi
cache-control: no-store
x-frame-options: DENY
x-xss-protection: 1;mode=block
x-content-type-options: nosniff
strict-transport-security: max-age=31536000;includeSubDomains;preload
referrer-policy: no-referrer-when-downgrade
body:
encoding: ''
file: no
string: '{"currentPage":1,"lastPage":1,"pageSize":100,"total":2,"results":[{"unit":{"unitId":"http://mus.utu.fi/MY.2475121"}},{"unit":{"unitId":"http://mus.utu.fi/MY.2475184"}}]}'
recorded_at: 2023-10-26 05:29:07 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
Loading

0 comments on commit dbd62ed

Please sign in to comment.