From 1b646e38df7bb16068377b622609e8df6a258048 Mon Sep 17 00:00:00 2001 From: wlandau Date: Thu, 9 Jan 2025 15:29:48 -0500 Subject: [PATCH] speed up verbose and timestamp reporters --- R/class_reporter.R | 2 +- R/class_timestamp.R | 14 +++++++------- R/class_verbose.R | 13 ++++++------- R/utils_cli.R | 7 +++++++ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/R/class_reporter.R b/R/class_reporter.R index dc6d0f20..7c55792d 100644 --- a/R/class_reporter.R +++ b/R/class_reporter.R @@ -76,4 +76,4 @@ reporter_class <- R6::R6Class( ) ) -reporter_seconds_skipped <- 0.25 +reporter_seconds_skipped <- 1 diff --git a/R/class_timestamp.R b/R/class_timestamp.R index ddf46ab7..b9507b8a 100644 --- a/R/class_timestamp.R +++ b/R/class_timestamp.R @@ -42,14 +42,14 @@ timestamp_class <- R6::R6Class( ) }, report_skipped = function(target, progress) { - self$buffer_message( - cli_skip( - target_get_name(target), - target_get_type_cli(target), - time_stamp = TRUE, - print = FALSE + now <- time_seconds_local() + skipped <- .subset2(.subset2(progress, "skipped"), "count") + if ((now - seconds_skipped) > reporter_seconds_skipped) { + self$buffer_message( + cli_skip_many(skipped = skipped, time_stamp = TRUE, print = FALSE) ) - ) + self$seconds_skipped <- now + } }, report_errored = function(target, progress = NULL) { self$buffer_message( diff --git a/R/class_verbose.R b/R/class_verbose.R index 97b276e4..c1dc2a04 100644 --- a/R/class_verbose.R +++ b/R/class_verbose.R @@ -41,13 +41,12 @@ verbose_class <- R6::R6Class( ) }, report_skipped = function(target, progress = NULL) { - self$buffer_message( - cli_skip( - target_get_name(target), - target_get_type_cli(target), - print = FALSE - ) - ) + now <- time_seconds_local() + skipped <- .subset2(.subset2(progress, "skipped"), "count") + if ((now - seconds_skipped) > reporter_seconds_skipped) { + self$buffer_message(cli_skip_many(skipped = skipped, print = FALSE)) + self$seconds_skipped <- now + } }, report_errored = function(target, progress = NULL) { self$buffer_message( diff --git a/R/utils_cli.R b/R/utils_cli.R index c22ea7f0..00264a59 100644 --- a/R/utils_cli.R +++ b/R/utils_cli.R @@ -40,6 +40,13 @@ cli_skip <- function(name, prefix = NULL, time_stamp = FALSE, print = TRUE) { cli_green_check(msg, print = print) } +cli_skip_many <- function(skipped, time_stamp = FALSE, print = TRUE) { + time <- if_any(time_stamp, time_stamp_cli(), NULL) + content <- sprintf("skipping targets (%s so far)...", skipped) + msg <- paste(c(time, content), collapse = " ") + cli_green_check(msg, print = print) +} + cli_error <- function(name, prefix = NULL, time_stamp = FALSE, print = TRUE) { time <- if_any(time_stamp, time_stamp_cli(), NULL) msg <- paste(c(time, "errored", prefix, name), collapse = " ")