aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-06-03 20:19:57 -0400
committerGeorge Claghorn <george@basecamp.com>2018-06-03 20:24:51 -0400
commitd3e0a9f11056c110b3a4bc0099da7ba165c0224f (patch)
treead7bcba6e7cdbec31f12f69b67ba73f79d5d3025 /activestorage
parentae028984d91a346067eac3d7f43d9ff3217bed11 (diff)
downloadrails-d3e0a9f11056c110b3a4bc0099da7ba165c0224f.tar.gz
rails-d3e0a9f11056c110b3a4bc0099da7ba165c0224f.tar.bz2
rails-d3e0a9f11056c110b3a4bc0099da7ba165c0224f.zip
Exclude upload time from instrumented preview time
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/lib/active_storage/previewer.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/activestorage/lib/active_storage/previewer.rb b/activestorage/lib/active_storage/previewer.rb
index bff5e42d41..13657bf13e 100644
--- a/activestorage/lib/active_storage/previewer.rb
+++ b/activestorage/lib/active_storage/previewer.rb
@@ -44,16 +44,17 @@ module ActiveStorage
#
# The output tempfile is opened in the directory returned by #tempdir.
def draw(*argv) #:doc:
- ActiveSupport::Notifications.instrument("preview.active_storage") do
- open_tempfile_for_drawing do |file|
+ open_tempfile do |file|
+ instrument :preview, key: blob.key do
capture(*argv, to: file)
- yield file
end
+
+ yield file
end
end
- def open_tempfile_for_drawing
- tempfile = Tempfile.open("ActiveStorage", tempdir)
+ def open_tempfile
+ tempfile = Tempfile.open("ActiveStorage-", tempdir)
begin
yield tempfile
@@ -62,6 +63,10 @@ module ActiveStorage
end
end
+ def instrument(operation, payload = {}, &block)
+ ActiveSupport::Notifications.instrument "#{operation}.active_storage", payload, &block
+ end
+
def capture(*argv, to:)
to.binmode
IO.popen(argv, err: File::NULL) { |out| IO.copy_stream(out, to) }