Skip to content

Commit

Permalink
Avoid the need to use blob package
Browse files Browse the repository at this point in the history
  • Loading branch information
wkmor1 committed Jul 25, 2024
1 parent df31cac commit 68fead4
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 42 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Imports:
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Suggests:
blob,
callr,
data.table,
DBI,
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ all: dev_deps R/sysdata.rda sentinels/check codemeta.json clean
dev_deps:
> ${RSCRIPT} -e "stopifnot(requireNamespace('callr', quietly = TRUE))";\
> ${RSCRIPT} -e "stopifnot(requireNamespace('codemetar', quietly = TRUE))";\
> ${RSCRIPT} -e "stopifnot(requireNamespace('blob', quietly = TRUE))";\
> ${RSCRIPT} -e "stopifnot(requireNamespace('data.table', quietly = TRUE))";\
> ${RSCRIPT} -e "stopifnot(requireNamespace('DBI', quietly = TRUE))";\
> ${RSCRIPT} -e "stopifnot(requireNamespace('details', quietly = TRUE))";\
Expand Down
26 changes: 20 additions & 6 deletions R/api_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,23 @@ api_get <- function(obj) {

} else {

stopifnot(
"{DBI} & {blob} needed to use a DB cache" = has_pkgs("DBI", "blob")
)
stopifnot("Package {DBI} needed to use a DB cache" = has_pkgs("DBI"))

if (!DBI::dbExistsTable(fcp, "finbif_cache")) {

blob <- list()

blob <- structure(
blob,
ptype = raw(),
class = c("blob", "vctrs_list_of", "vctrs_vctr", "list")
)

init <- data.frame(
hash = character(),
created = as.POSIXct(numeric()),
timeout = numeric(),
blob = blob::blob()
blob = blob
)

DBI::dbWriteTable(fcp, "finbif_cache", init)
Expand Down Expand Up @@ -418,17 +424,25 @@ cache_obj <- function(obj) {

append_obj <- function(obj) {

hash <- obj[["hash"]]

if (!is.null(obj)) {

blob <- serialize(obj, NULL)

hash <- obj[["hash"]]
blob <- list(blob)

blob <- structure(
blob,
ptype = raw(),
class = c("blob", "vctrs_list_of", "vctrs_vctr", "list")
)

db_cache <- data.frame(
hash = hash,
created = Sys.time(),
timeout = obj[["timeout"]],
blob = blob::blob(blob)
blob = blob
)

debug_msg("INFO [", format(Sys.time()), "] ", "Adding to cache: ", hash)
Expand Down
8 changes: 4 additions & 4 deletions R/caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#'
#' @section Using database caching:
#' Caching can also be done using a database. Using a database for caching
#' requires the packages `DBI`, `blob` and a database backend package such as
#' `RSQLite` to be installed. To use the database for caching simply pass the
#' connection objected created with `DBI::dbConnect` to the `finbif_cache_path`
#' option (e.g.,
#' requires the `DBI` package and a database backend package such as `RSQLite`
#' to be installed. To use the database for caching simply pass the connection
#' objected created with `DBI::dbConnect` to the `finbif_cache_path` option
#' (e.g.,
#' `db <- DBI::dbConnect(RSQLite::SQLite(), "my-db.sqlite"); `
#' `options(finbif_cache_path = db)`
#' ).
Expand Down
4 changes: 1 addition & 3 deletions R/finbif_clear_cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ finbif_clear_cache <- function() {

} else {

has_dbi <- has_pkgs("DBI", "blob")

stopifnot("Packages {DBI} & {blob} needed to use a DB cache" = has_dbi)
stopifnot("Package {DBI} needed to use a DB cache" = has_pkgs("DBI"))

if (DBI::dbExistsTable(fcp, "finbif_cache")) {

Expand Down
4 changes: 1 addition & 3 deletions R/finbif_update_cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ finbif_update_cache <- function() {

} else {

has_dbi <- has_pkgs("DBI", "blob")

stopifnot("Packages {DBI} & {blob} needed to use a DB cache" = has_dbi)
stopifnot("Package {DBI} needed to use a DB cache" = has_pkgs("DBI"))

if (DBI::dbExistsTable(fcp, "finbif_cache")) {

Expand Down
14 changes: 1 addition & 13 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@
}
],
"softwareSuggestions": [
{
"@type": "SoftwareApplication",
"identifier": "blob",
"name": "blob",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=blob"
},
{
"@type": "SoftwareApplication",
"identifier": "callr",
Expand Down Expand Up @@ -258,7 +246,7 @@
"applicationCategory": "Biodiversity",
"isPartOf": "https://species.fi",
"keywords": ["api", "biodiversity", "biodiversity-informatics", "biodiversity-information", "finbif", "finbif-access", "occurrences", "r-package", "r-programming", "rstats", "species", "specimens", "taxon", "taxonomy", "web-services"],
"fileSize": "12039.505KB",
"fileSize": "12040.567KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
2 changes: 1 addition & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ articles:
v03_selecting_variables: v03_selecting_variables.html
v04_metadata: v04_metadata.html
v05_filtering: v05_filtering.html
last_built: 2024-07-23T12:03Z
last_built: 2024-07-25T09:04Z
urls:
reference: https://finbif-docs-dev.netlify.app/reference
article: https://finbif-docs-dev.netlify.app/articles
8 changes: 4 additions & 4 deletions docs/reference/caching.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions man/caching.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 68fead4

Please sign in to comment.