Skip to content

Commit

Permalink
reference efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 21, 2024
1 parent 2e124b8 commit 72e6ce0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
4 changes: 2 additions & 2 deletions R/class_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pipeline_targets_init <- function(targets, clone_targets) {

pipeline_get_target <- function(pipeline, name) {
out <- .subset2(.subset2(pipeline, "targets"), name)
if (is_reference(out)) {
if (is_reference_not_target(out)) {
out <- reference_produce_target(out, pipeline, name)
}
out
Expand Down Expand Up @@ -162,7 +162,7 @@ pipeline_register_loaded <- function(pipeline, name) { # nolint

pipeline_unload_target <- function(pipeline, name) {
target <- .subset2(.subset2(pipeline, "targets"), name)
if (!is_reference(target)) {
if (!is_reference_not_target(target)) {
store_unload(target$store, target)
pipeline_set_reference(pipeline, target)
}
Expand Down
24 changes: 6 additions & 18 deletions R/class_reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,23 @@ reference_new <- function(
stage = NULL,
hash = NULL
) {
out <- list(parent = parent)
if (!is.null(path)) {
out$path <- path
}
if (!is.null(stage)) {
out$stage <- stage
}
if (!is.null(hash)) {
out$hash <- hash
}
out
list(parent, path, stage, hash)
}

reference_parent <- function(reference) {
.subset2(reference, "parent")
.subset2(reference, 1L)
}

reference_path <- function(reference) {
.subset2(reference, "path")
.subset2(reference, 2L)
}

reference_stage <- function(reference) {
.subset2(reference, "stage")
.subset2(reference, 3L)
}

reference_hash <- function(reference) {
.subset2(reference, "hash")
.subset2(reference, 4L)
}

reference_produce_target <- function(reference, pipeline, name) {
Expand All @@ -57,6 +47,4 @@ reference_produce_target <- function(reference, pipeline, name) {
child
}

is_reference <- function(reference) {
is.list(reference) && is.character(reference_parent(reference))
}
is_reference_not_target <- is.list

0 comments on commit 72e6ce0

Please sign in to comment.