Skip to content

Commit

Permalink
speed up store_sync_file_meta()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jan 3, 2025
1 parent fa99d27 commit e74d738
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
3 changes: 3 additions & 0 deletions R/class_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ meta_class <- R6::R6Class(
insert_record = function(record) {
self$database$buffer_row(record_produce_row(record))
},
insert_row = function(row) {
.subset2(.subset2(self, "database"), "buffer_row")(row)
},
exists_record = function(name) {
self$database$exists_row(name)
},
Expand Down
35 changes: 21 additions & 14 deletions R/class_store.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,30 +404,37 @@ store_sync_file_meta <- function(store, target, meta) {

#' @export
store_sync_file_meta.default <- function(store, target, meta) {
cue <- target$cue
if (identical(cue$mode, "never") || identical(cue$file, FALSE)) {
cue <- .subset2(target, "cue")
if ((.subset2(cue, "mode") == "never") || (!.subset2(cue, "file"))) {
return()
}
name <- target_get_name(target)
record <- meta$get_record(name)
row <- .subset2(meta, "get_row")(name)
path <- store_path_from_name(
store = .subset2(target, "store"),
format = .subset2(row, "format"),
name = name,
path = unlist(.subset2(row, "path")),
path_store = .subset2(meta, "store")
)
file <- file_init(
path = record$path,
time = record$time,
size = record$size,
bytes = record$bytes
path = path,
time = .subset2(row, "time"),
size = .subset2(row, "size"),
bytes = .subset2(row, "bytes")
)
info <- file_info_runtime(target$file$path)
info <- file_info_runtime(.subset2(.subset2(target, "file"), "path"))
time <- file_time(info)
bytes <- file_bytes(info)
size <- file_size(bytes)
# Fully automated tests do no use big files.
# Fully automated tests do no use big enough files.
# Tested in tests/interactive/test-file.R. # nolint
# nocov start
if (!identical(time, file$time) || !identical(size, file$size)) {
record$time <- time
record$size <- size
record$bytes <- bytes
meta$insert_record(record)
if ((time != .subset2(file, "time")) || (size != .subset2(file, "size"))) {
row$time <- time
row$size <- size
row$bytes <- bytes
.subset2(meta, "insert_row")(row)
}
# nocov end
}
Expand Down

0 comments on commit e74d738

Please sign in to comment.