diff --git a/DESCRIPTION b/DESCRIPTION index aa96607..609f6ed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tarflow.iquizoo Title: Setup "targets" Workflows for "iquizoo" Data Processing -Version: 3.12.1 +Version: 3.12.2 Authors@R: c( person("Liang", "Zhang", , "psychelzh@outlook.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9041-1150")), @@ -20,7 +20,6 @@ Depends: Imports: cachem, cli, - data.iquizoo (>= 2024.3.31.2), DBI, glue, jsonlite, @@ -31,16 +30,15 @@ Imports: Suggests: bit64, covr, + data.iquizoo (>= 2024.7.14), digest, lifecycle, odbc, preproc.iquizoo (>= 2.6.0), - purrr, RMariaDB (>= 1.3.1), roxygen2, testthat (>= 3.0.0), - tibble, - withr + tibble Remotes: psychelzh/data.iquizoo, psychelzh/preproc.iquizoo diff --git a/NEWS.md b/NEWS.md index 508f71d..b51eeda 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# tarflow.iquizoo 3.12.2 + +## Enhancements + +* Added a default expiration time for disk cache in `fetch_iquizoo_mem()` of 7 days. + +## Misc + +* Moved data.iquizoo to Suggests. The logic behind is the same as that of preproc.iquizoo. + # tarflow.iquizoo 3.12.1 ## Enhancements diff --git a/R/database.R b/R/database.R index 9a38340..4ddb718 100644 --- a/R/database.R +++ b/R/database.R @@ -49,9 +49,10 @@ fetch_iquizoo <- function(query, ..., #' @param cache The cache to be used. Default cache could be configured by #' setting the environment variable `TARFLOW_CACHE` to `"disk"` or `"memory"`. #' If set `TARFLOW_CACHE` to `"disk"`, the cache will be stored in disk at -#' `~/.cache/tarflow.iquizoo`. If set `TARFLOW_CACHE` to `"memory"`, the cache -#' will be stored in memory. You can also set `cache` to a custom cache, see -#' [memoise::memoise()] for more details. +#' `~/.cache/tarflow.iquizoo` with a maximal age of 7 days. If set +#' `TARFLOW_CACHE` to `"memory"`, the cache will be stored in memory. You can +#' also set `cache` to a custom cache, see [memoise::memoise()] for more +#' details. #' @return A memoised version of [fetch_iquizoo()]. #' @seealso [fetch_iquizoo()] for the original function. #' @export @@ -59,7 +60,10 @@ fetch_iquizoo_mem <- function(cache = NULL) { requireNamespace("digest", quietly = TRUE) if (is.null(cache)) { cache <- switch(Sys.getenv("TARFLOW_CACHE", "disk"), - disk = cachem::cache_disk("~/.cache/tarflow.iquizoo"), + disk = cachem::cache_disk( + "~/.cache/tarflow.iquizoo", + max_age = 3600 * 24 * 7 # 7 days + ), memory = cachem::cache_mem() ) } diff --git a/R/targets.R b/R/targets.R index 44696e7..41a9625 100644 --- a/R/targets.R +++ b/R/targets.R @@ -107,12 +107,7 @@ tar_prep_iquizoo <- function(params, contents, ..., targets, lapply( intersect(combine, names(targets)), - \(name) { - tarchetypes::tar_combine_raw( - name, - targets[[name]] - ) - } + \(name) tarchetypes::tar_combine_raw(name, targets[[name]]) ) ) } @@ -296,7 +291,10 @@ tar_prep_raw <- function(contents, ) }, indices = if ("preproc" %in% action_raw_data) { - check_installed("preproc.iquizoo", "becasue required in pre-processing.") + check_installed( + c("preproc.iquizoo", "data.iquizoo"), + "becasue required in pre-processing." + ) tarchetypes::tar_eval( targets::tar_target( tar_indices, diff --git a/inst/sql/progress_hash.sql b/inst/sql/progress_hash.sql index 1b66092..4831c53 100644 --- a/inst/sql/progress_hash.sql +++ b/inst/sql/progress_hash.sql @@ -1,6 +1,6 @@ SELECT - MD5(concat_ws(", ", pcc.Id, FinishedUserCount, ConfiguredUserCount, Progress, CompletionRate)) AS MD5 + MD5(concat_ws(", ", Id, FinishedUserCount, ConfiguredUserCount, Progress, CompletionRate)) AS MD5 FROM - iquizoo_business_db.project_course_config pcc + iquizoo_business_db.project_course_config WHERE - pcc.Id = ?; + Id = ?; diff --git a/inst/sql/users.sql b/inst/sql/users.sql index efcc161..f34da3f 100644 --- a/inst/sql/users.sql +++ b/inst/sql/users.sql @@ -12,5 +12,6 @@ FROM AND organization_user.Deleted <> 1 INNER JOIN iquizoo_user_db.base_organization ON base_organization.Id = organization_user.OrganizationId + AND base_organization.Deleted <> 1 WHERE project_course_config.Id = ?; diff --git a/man/fetch_iquizoo_mem.Rd b/man/fetch_iquizoo_mem.Rd index c4ac02f..9438f12 100644 --- a/man/fetch_iquizoo_mem.Rd +++ b/man/fetch_iquizoo_mem.Rd @@ -10,9 +10,10 @@ fetch_iquizoo_mem(cache = NULL) \item{cache}{The cache to be used. Default cache could be configured by setting the environment variable \code{TARFLOW_CACHE} to \code{"disk"} or \code{"memory"}. If set \code{TARFLOW_CACHE} to \code{"disk"}, the cache will be stored in disk at -\verb{~/.cache/tarflow.iquizoo}. If set \code{TARFLOW_CACHE} to \code{"memory"}, the cache -will be stored in memory. You can also set \code{cache} to a custom cache, see -\code{\link[memoise:memoise]{memoise::memoise()}} for more details.} +\verb{~/.cache/tarflow.iquizoo} with a maximal age of 7 days. If set +\code{TARFLOW_CACHE} to \code{"memory"}, the cache will be stored in memory. You can +also set \code{cache} to a custom cache, see \code{\link[memoise:memoise]{memoise::memoise()}} for more +details.} } \value{ A memoised version of \code{\link[=fetch_iquizoo]{fetch_iquizoo()}}. diff --git a/tests/testthat/helper-expections.R b/tests/testthat/helper-expections.R index adbe9b5..5f87fdc 100644 --- a/tests/testthat/helper-expections.R +++ b/tests/testthat/helper-expections.R @@ -5,10 +5,12 @@ expect_targets_list <- function(targets) { sprintf("%s should be a list, not a %s.", act$lab, typeof(act$val)) ) } - if (!all(purrr::map_lgl(unlist(act$val), \(x) inherits(x, "tar_target")))) { - testthat::fail( - sprintf("All elements of %s should be valid target objects.", act$lab) - ) + for (val in unlist(act$val)) { + if (!inherits(val, "tar_target")) { + testthat::fail( + sprintf("All elements of %s should be valid target objects.", act$lab) + ) + } } testthat::succeed() invisible(act$val) diff --git a/tests/testthat/test_basic-cases.R b/tests/testthat/test_basic-cases.R index 0e98f55..d5433cb 100644 --- a/tests/testthat/test_basic-cases.R +++ b/tests/testthat/test_basic-cases.R @@ -41,13 +41,12 @@ targets::tar_test("`combine` work properly", { }) targets::tar_test("Serialize check (no roundtrip error)", { - withr::local_envvar(c(TARFLOW_CACHE = "memory")) targets::tar_script({ params <- tibble::tribble( ~organization_name, ~project_name, ~course_name, ~game_name, "四川省双流棠湖中学高中部", "棠湖中学英才计划测训体验账号", NA, NA ) - tar_prep_iquizoo(params)[1] + tar_prep_iquizoo(params, cache = cachem::cache_mem())[1] }) targets::tar_make(reporter = "silent", callr_function = NULL) expect_identical(