From 9ec574c42c71d4faa1cbaa29b7ca721514425909 Mon Sep 17 00:00:00 2001 From: Jan Jedrychowski Date: Sun, 14 Jun 2020 01:55:31 +0200 Subject: [PATCH 1/3] Relative path calculation on the backend --- meta_request/lib/meta_request/app_notifications.rb | 4 +++- meta_request/lib/meta_request/utils.rb | 5 +++++ meta_request/spec/meta_request/utils_spec.rb | 6 ++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/meta_request/lib/meta_request/app_notifications.rb b/meta_request/lib/meta_request/app_notifications.rb index 2eb0f49..2769917 100644 --- a/meta_request/lib/meta_request/app_notifications.rb +++ b/meta_request/lib/meta_request/app_notifications.rb @@ -49,7 +49,9 @@ class AppNotifications VIEW_BLOCK = proc { |*args| name, start, ending, transaction_id, payload = args - payload[:identifier] = MetaRequest::Utils.sub_source_path(payload[:identifier]) + identifier = payload[:identifier] + payload[:identifier] = MetaRequest::Utils.sub_source_path(identifier) + payload[:relative_identifier] = MetaRequest::Utils.relative_path(identifier) Event.new(name, start, ending, transaction_id, payload) } diff --git a/meta_request/lib/meta_request/utils.rb b/meta_request/lib/meta_request/utils.rb index 2f4bd8f..b760d52 100644 --- a/meta_request/lib/meta_request/utils.rb +++ b/meta_request/lib/meta_request/utils.rb @@ -12,6 +12,7 @@ def dev_callsite(caller) { filename: sub_source_path(filename), + relative_filename: relative_path(filename), line: line.to_i, method: method } @@ -24,5 +25,9 @@ def sub_source_path(path) path.sub(rails_root, source_path) end + + def relative_path(path) + path.sub(MetaRequest.rails_root, '').sub(%r{\A/}, '') + end end end diff --git a/meta_request/spec/meta_request/utils_spec.rb b/meta_request/spec/meta_request/utils_spec.rb index 48077e7..ab39431 100644 --- a/meta_request/spec/meta_request/utils_spec.rb +++ b/meta_request/spec/meta_request/utils_spec.rb @@ -15,7 +15,8 @@ ] expect(MetaRequest::Utils.dev_callsite(stacktrace)).to eq( - filename: filename, line: line, method: method + filename: filename, relative_filename: 'test_file.rb', + line: line, method: method ) end @@ -39,7 +40,8 @@ ] expect(MetaRequest::Utils.dev_callsite(stacktrace)).to eq( - filename: '/Users/foo/bar/test_file.rb', line: line, method: method + filename: '/Users/foo/bar/test_file.rb', + relative_filename: 'test_file.rb', line: line, method: method ) # revert configuration From 126841097ca8ff6e541157f207afd5cb9353a8bf Mon Sep 17 00:00:00 2001 From: Jan Jedrychowski Date: Sun, 14 Jun 2020 02:47:25 +0200 Subject: [PATCH 2/3] Relative path - frontend handling --- rails_panel/panel.html | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/rails_panel/panel.html b/rails_panel/panel.html index 60253bc..eb5e47d 100644 --- a/rails_panel/panel.html +++ b/rails_panel/panel.html @@ -160,7 +160,10 @@ - {{sql.payload.filename | normalizePath}}:{{sql.payload.line}} + + {{ sql.payload.filename | normalizePath}}:{{sql.payload.line}} + {{ sql.payload.relative_filename}}:{{sql.payload.line}} + {{sql.payload.name}} @@ -185,7 +188,10 @@ - {{view.payload.identifier | normalizePath}} + + {{view.payload.identifier | normalizePath}} + {{view.payload.relative_identifier}} + within {{view.payload.layout}} {{view.duration | number:0}} ms @@ -209,7 +215,10 @@ - {{cache.payload.filename | normalizePath}}:{{cache.payload.line}} + + {{cache.payload.filename | normalizePath}}:{{cache.payload.line}} + {{cache.payload.relative_filename}}:{{cache.payload.line}} + {{cache.payload.type}} @@ -231,7 +240,10 @@ - {{log.payload.filename | normalizePath}}:{{log.payload.line}} + + {{log.payload.filename | normalizePath}}:{{log.payload.line}} + {{log.payload.relative_filename}}:{{log.payload.line}} + From 1d8e8c40cd36c75736c3471ccba797fde3932c07 Mon Sep 17 00:00:00 2001 From: Jan Jedrychowski Date: Sun, 14 Jun 2020 02:50:02 +0200 Subject: [PATCH 3/3] Fix root path relative calculation --- meta_request/lib/meta_request/utils.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meta_request/lib/meta_request/utils.rb b/meta_request/lib/meta_request/utils.rb index b760d52..41d3897 100644 --- a/meta_request/lib/meta_request/utils.rb +++ b/meta_request/lib/meta_request/utils.rb @@ -23,11 +23,11 @@ def sub_source_path(path) source_path = MetaRequest.config.source_path return path if rails_root == source_path - path.sub(rails_root, source_path) + path.sub(%r{\A#{rails_root}}, source_path) end def relative_path(path) - path.sub(MetaRequest.rails_root, '').sub(%r{\A/}, '') + path.sub(%r{\A#{MetaRequest.rails_root}/?}, '') end end end