@@ -156,7 +156,6 @@ collect_layer <- function(
156
156
page_size = NULL ,
157
157
... ,
158
158
error_call = rlang :: caller_env()) {
159
-
160
159
# 1. Make base request
161
160
# 2. Identify necessary query parameters
162
161
# 3. Figure out offsets and update query parameters
@@ -203,28 +202,22 @@ collect_layer <- function(
203
202
# Offsets -----------------------------------------------------------------
204
203
205
204
# count the number of features in a query
206
- n_feats <- count_results(req , query_params , n_max = n_max , error_call = error_call )
205
+ n_feats <- count_results(
206
+ req = req ,
207
+ query = query_params ,
208
+ n_max = n_max ,
209
+ error_call = error_call
210
+ )
207
211
208
- # create a list of record counts based on number of features, page size and max records
209
- record_offsets <- set_record_offsets(
212
+ all_resps <- get_query_resps(
213
+ x = x ,
214
+ req = req ,
210
215
n_feats = n_feats ,
211
216
page_size = page_size ,
212
- max_records = x [[ " maxRecordCount " ]] ,
217
+ query_params = query_params ,
213
218
error_call = error_call
214
219
)
215
220
216
- # create a list of requests from the offset and page sizes
217
- all_requests <- mapply(
218
- add_offset ,
219
- .offset = record_offsets [[" offsets" ]],
220
- .page_size = record_offsets [[" counts" ]],
221
- MoreArgs = list (.req = req , .params = query_params ),
222
- SIMPLIFY = FALSE
223
- )
224
-
225
- # make all requests and store responses in list
226
- all_resps <- httr2 :: req_perform_parallel(all_requests , on_error = " continue" )
227
-
228
221
# identify any errors
229
222
# TODO: determine how to handle errors
230
223
# has_error <- vapply(all_resps, function(x) inherits(x, "error"), logical(1))
@@ -264,6 +257,62 @@ collect_layer <- function(
264
257
res
265
258
}
266
259
260
+ # ' Get query responses with handling for layers that don't support pagination
261
+ # ' @noRd
262
+ get_query_resps <- function (
263
+ req ,
264
+ x ,
265
+ n_feats ,
266
+ page_size = NULL ,
267
+ query_params = list (),
268
+ error_call = rlang :: caller_env()) {
269
+ # If pagination is not supported, we create one query and return the results
270
+ # in a list with a warning. This way the maximum number of results is returned
271
+ # but the user is also informed that they will not get tha maximum number of
272
+ # records. Otherwise, we continue and utilize the pagination
273
+ if (isFALSE(x [[" advancedQueryCapabilities" ]][[" supportsPagination" ]])) {
274
+ if (n_feats > x [[" maxRecordCount" ]]) {
275
+ cli :: cli_warn(
276
+ c(
277
+ " {class(x)} {.val {x[['name']]}} does not support pagination and
278
+ complete results can't be returned." ,
279
+ " i" = " {n_feats} features are selected by the query and the maximum
280
+ is {x[['maxRecordCount']]} records."
281
+ )
282
+ )
283
+ }
284
+
285
+ req <- httr2 :: req_body_form(
286
+ httr2 :: req_url_path_append(req , " query" ),
287
+ !!! query_params
288
+ )
289
+
290
+ resp <- httr2 :: req_perform(req , error_call = error_call )
291
+
292
+ return (list (resp ))
293
+ }
294
+
295
+ # create a list of record counts based on number of features, page size and max records
296
+ record_offsets <- set_record_offsets(
297
+ n_feats = n_feats ,
298
+ page_size = page_size ,
299
+ max_records = x [[" maxRecordCount" ]],
300
+ error_call = error_call
301
+ )
302
+
303
+ # create a list of requests from the offset and page sizes
304
+ all_requests <- mapply(
305
+ add_offset ,
306
+ .offset = record_offsets [[" offsets" ]],
307
+ .page_size = record_offsets [[" counts" ]],
308
+ MoreArgs = list (.req = req , .params = query_params ),
309
+ SIMPLIFY = FALSE
310
+ )
311
+
312
+ # make all requests and store responses in list
313
+ httr2 :: req_perform_parallel(all_requests , on_error = " continue" )
314
+ }
315
+
267
316
268
317
# utility -----------------------------------------------------------------
269
318
@@ -425,8 +474,7 @@ count_results <- function(req, query, n_max = Inf, error_call = rlang::caller_en
425
474
validate_results_count <- function (
426
475
n_results = NULL ,
427
476
n_max = Inf ,
428
- error_call = rlang :: caller_env()
429
- ) {
477
+ error_call = rlang :: caller_env()) {
430
478
if (is.null(n_results )) {
431
479
cli :: cli_abort(
432
480
c(
0 commit comments