Skip to content

Commit 4e0a932

Browse files
authored
Merge pull request #19 from conbench/aus/history_pag
add pagination to history()
2 parents d737097 + af4151c commit 4e0a932

File tree

7 files changed

+44
-35
lines changed

7 files changed

+44
-35
lines changed

Diff for: DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: conbenchcoms
22
Title: An API wrapper for conbench communications
3-
Version: 0.0.7
3+
Version: 0.0.8
44
Authors@R: c(
55
person("Jonathan", "Keane", , "[email protected]", role = c("aut", "ctb"),
66
comment = c(ORCID = "0000-0001-7087-9776")),

Diff for: NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# conbenchcoms 0.0.8
2+
* Remove `simplifyVector` and `flatten` arguments from `history`
3+
* `history` now always returns a `tibble`
4+
* `history` now paginates until all matching data is returned, which works only with Conbench servers of at least version [649a9ac](https://github.com/conbench/conbench/commit/649a9ac)
5+
16
# conbenchcoms 0.0.7
27
* Remove `sha`, `simplifyVector`, and `flatten` arguments from `runs`
38
* Add `commit_hashes` argument to `runs`

Diff for: R/history.R

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
#' Get history for a benchmark
22
#'
3-
#' @param benchmark_id the hash of a benchmark to get the history for
4-
#' @inheritParams jsonlite::fromJSON
3+
#' @param benchmark_id the ID of a benchmark result to get the history for
54
#'
6-
#' @return the response
5+
#' @return a tibble of history
76
#' @export
8-
history <- function(benchmark_id, simplifyVector = TRUE, flatten = TRUE, ...) {
7+
history <- function(benchmark_id) {
98
req <- req_url_path_append(conbench_request(), "history", benchmark_id)
10-
9+
req <- req_url_query(req, page_size = 1000)
1110
resp <- conbench_perform(req)
11+
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
12+
data <- dplyr::as_tibble(json[["data"]])
13+
14+
while (!is.null(json[["metadata"]][["next_page_cursor"]])) {
15+
req <- req_url_path_append(conbench_request(), "history", benchmark_id)
16+
req <- req_url_query(
17+
req,
18+
page_size = 1000,
19+
cursor = json[["metadata"]][["next_page_cursor"]]
20+
)
21+
resp <- conbench_perform(req)
22+
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
23+
data <- dplyr::bind_rows(data, dplyr::as_tibble(json[["data"]]))
24+
}
1225

13-
resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
26+
data
1427
}

Diff for: man/history.Rd

+3-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"data": [
3+
{
4+
"benchmark_id": "hist-id",
5+
"timestamp": "2022-04-07T21:11:19",
6+
"unit": "s"
7+
}
8+
],
9+
"metadata": {
10+
"next_page_cursor": null
11+
}
12+
}

Diff for: tests/testthat/resp-class/localhost/api/history/hist-id.json

-7
This file was deleted.

Diff for: tests/testthat/test-history.R

+4-12
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,20 @@ with_mock_dir(test_path("logged-in"), {
22
test_that("history()", {
33
expect_GET(
44
history("C0C0A"),
5-
"http://localhost/api/history/C0C0A"
5+
"http://localhost/api/history/C0C0A?page_size=1000"
66
)
77
})
88
})
99

1010

1111
with_mock_dir(test_path("resp-class"), {
1212
the_id <- "hist-id"
13-
test_that("history() returns a data.frame", {
13+
test_that("history() returns a tibble", {
1414
the_history <- history(benchmark_id = the_id)
1515
expect_s3_class(
1616
the_history,
17-
"data.frame"
17+
"tbl_df"
1818
)
1919
expect_identical(the_id, the_history$benchmark_id)
2020
})
21-
test_that("history(...,simplifyVector = FALSE, flatten = FALSE) returns a list", {
22-
the_list_history <- history(benchmark_id = the_id, simplifyVector = FALSE, flatten = FALSE)
23-
expect_type(
24-
the_list_history,
25-
"list"
26-
)
27-
expect_identical(the_id, the_list_history[[1]]$benchmark_id)
28-
})
29-
})
21+
})

0 commit comments

Comments
 (0)