Skip to content

Commit

Permalink
Prevent queries beyond last page
Browse files Browse the repository at this point in the history
  • Loading branch information
wkmor1 committed Sep 2, 2024
1 parent fca9275 commit f1b9fa4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions R/finbif_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@ get_extra_pages <- function(fb_records_list) {

page <- query[["page"]]

last_page <- ceiling(n_tot / query[["pageSize"]])

use_future <- has_pkgs("future") && getOption("finbif_use_async")

if (use_future) {
Expand All @@ -866,11 +868,17 @@ get_extra_pages <- function(fb_records_list) {

ids <- character()

while (n_needed > (n_got - length(which(duplicated(ids))))) {
more_pages <- TRUE

while (n_needed > n_got - length(which(duplicated(ids))) && more_pages) {

page <- page + 1L

if (sample && page > ceiling(n_tot / query[["pageSize"]])) {
sampling_failed <- sample && page > last_page

if (sampling_failed) {

sample <- FALSE

page <- 1L

Expand Down Expand Up @@ -898,11 +906,7 @@ get_extra_pages <- function(fb_records_list) {

}

if (attr(fb_records_list, "df", TRUE)) {

attr(fb_records_list[[i]], "df") <- records_df(fb_records_list[[i]])

}
attr(fb_records_list[[i]], "df") <- records_df(fb_records_list[[i]])

records_i <- value(res)

Expand All @@ -924,6 +928,8 @@ get_extra_pages <- function(fb_records_list) {

n_got <- n_got + length(records_i[[c("content", "results")]])

more_pages <- page < last_page || sample

}

fb_records_list
Expand Down

0 comments on commit f1b9fa4

Please sign in to comment.