From 8823aa802eb0b03b29858686a5a18ebe30447af7 Mon Sep 17 00:00:00 2001 From: jonathannewman Date: Wed, 15 May 2024 14:51:42 -0700 Subject: [PATCH] (maint) include expensive calculation in logging level check This moves a potentially expensive (when there are lots of nested directories and lots of changes) into the logging level check to avoid calculating it if it isn't needed. --- .../services/watcher/filesystem_watch_core.clj | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/clj/puppetlabs/trapperkeeper/services/watcher/filesystem_watch_core.clj b/src/clj/puppetlabs/trapperkeeper/services/watcher/filesystem_watch_core.clj index 6f05d82..b3e03df 100644 --- a/src/clj/puppetlabs/trapperkeeper/services/watcher/filesystem_watch_core.clj +++ b/src/clj/puppetlabs/trapperkeeper/services/watcher/filesystem_watch_core.clj @@ -145,23 +145,24 @@ events)) initial-events))) - (schema/defn process-events! - "Process for side-effects any events that occured for watcher's watch-key" + "Process for side effects any events that occurred for watcher's watch-key" [watcher :- (schema/protocol Watcher) events :- [Event]] - (let [callbacks @(:callbacks watcher) - events-by-dir (group-by :watched-path events)] + (let [callbacks @(:callbacks watcher)] ;; avoid doing a potentially expensive walk when we aren't logging at :debug (when (log/enabled? :debug) - (doseq [[dir events'] events-by-dir] - (log/debug (trs "Got {0} event(s) in directory {1}" - (count events') dir)))) + (let [events-by-dir (group-by :watched-path events)] + (doseq [[dir events'] events-by-dir] + (log/debug (trs "Got {0} event(s) in directory {1}" + (count events') dir))))) + ;; avoid doing a potentially expensive print-to-string when we aren't logging at :trace (when (log/enabled? :trace) (log/tracef "%s\n%s" (trs "Events:") (ks/pprint-to-string events))) + (doseq [callback callbacks] (callback events))))