Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pagination error in REST API's #2952

Merged
merged 9 commits into from
Jan 11, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ We are slowly change the license from NCSA opensource to BSD-3 to help with publ
- rstudio was not working behind traefik.
- plots now work in docker containers
- when specifying diferent rstudio user, dev setup would mount pecan folder in wrong path.
- fixed the pagination error in the next_page field of the workflows, inputs and runs Rest API.
- bugs in `model2ncdf.ED2()` that were causing it to both error and also only
convert data for a single PFT fixed (#1329, #2974, #2981)
- Code cleanup in PEcAn.MA to protect against global namespace pollution (#2965, #2973; @nanu1605)
Expand Down
37 changes: 26 additions & 11 deletions apps/api/R/inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,37 @@ searchInputs <- function(req, model_id=NA, site_id=NA, format_id=NA, host_id=NA,
result <- list(inputs = qry_res)
result$count <- nrow(qry_res)
if(has_next){
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/workflows",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
if(grepl("offset=", req$QUERY_STRING, fixed = TRUE)){
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/inputs",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
}
else {
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/inputs",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "limit=")[[2]] - 6),
"offset=",
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
}
}
if(has_prev) {
result$prev_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/workflows",
"/api/inputs",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
max(0, (as.numeric(offset) - as.numeric(limit))),
Expand Down
35 changes: 25 additions & 10 deletions apps/api/R/runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,31 @@ getRuns <- function(req, workflow_id=NA, offset=0, limit=50, res){
result <- list(runs = qry_res)
result$count <- nrow(qry_res)
if(has_next){
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/runs",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
if(grepl("offset=", req$QUERY_STRING, fixed = TRUE)){
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/runs",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
}
else {
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/runs",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "limit=")[[2]] - 6),
"offset=",
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
}
}
if(has_prev) {
result$prev_page <- paste0(
Expand Down
37 changes: 26 additions & 11 deletions apps/api/R/workflows.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,31 @@ getWorkflows <- function(req, model_id=NA, site_id=NA, offset=0, limit=50, res){
result <- list(workflows = qry_res)
result$count <- nrow(qry_res)
if(has_next){
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/workflows",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
if(grepl("offset=", req$QUERY_STRING, fixed = TRUE)){
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/workflows",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "offset=")[[2]]),
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
}
else {
result$next_page <- paste0(
req$rook.url_scheme, "://",
req$HTTP_HOST,
"/api/workflows",
req$PATH_INFO,
substr(req$QUERY_STRING, 0, stringr::str_locate(req$QUERY_STRING, "limit=")[[2]] - 6),
"offset=",
(as.numeric(limit) + as.numeric(offset)),
"&limit=",
limit
)
}
}
if(has_prev) {
result$prev_page <- paste0(
Expand Down Expand Up @@ -200,7 +215,7 @@ getWorkflowStatus <- function(req, id, res){
#* @get /<id>/file/<filename>
getWorkflowFile <- function(req, id, filename, res){
Workflow <- tbl(global_db_pool, "workflows") %>%
select(id, user_id) %>%
select(id, user_id) %>%
filter(id == !!id)

qry_res <- Workflow %>% collect()
Expand Down