Skip to content

Commit

Permalink
Avoid redundant validation of child objects when saving the parent.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Aug 1, 2024
1 parent 037da92 commit 7f4d5b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,24 @@ setGeneric("saveObject", function(x, path, ...) {
}
}

# Only validate once we're outside of nested calls, as each parent should
# validate its children; separate validation of each child is redundant.
do_validate <- !is_nested$status
if (do_validate) {
is_nested$status <- TRUE
on.exit({ is_nested$status <- FALSE }, add=TRUE, after=FALSE)
}

standardGeneric("saveObject")
validateObject(path)

if (do_validate) {
validateObject(path)
}
})

is_nested <- new.env()
is_nested$status <- FALSE

#######################################
########### OLD STUFF HERE ############
#######################################
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ test_that("staging of weird objects within DFs works correctly", {

# Works in the new world.
tmp2 <- tempfile()
saveObject(df, tmp2)
saveObject(input, tmp2)
expect_identical(readObjectFile(tmp2)$type, "data_frame")
round2 <- readDataFrame(tmp2)
expect_identical(round2, df)
expect_identical(round2, input)
})

test_that("staging of uncompressed Gzip works correctly", {
Expand Down

0 comments on commit 7f4d5b3

Please sign in to comment.