From 4543ed2afcec1e16748d7c44f049e7515d179795 Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Mon, 25 May 2020 05:40:37 +0300 Subject: [PATCH] FIX: Fix client timings regression and bring back 'show trivial' (#441) --- lib/html/includes.js | 66 ++++++++++++++++++------------ lib/html/includes.tmpl | 4 +- lib/html/vendor.js | 2 +- lib/mini_profiler/asset_version.rb | 2 +- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/lib/html/includes.js b/lib/html/includes.js index 723cfb13..e5930d09 100644 --- a/lib/html/includes.js +++ b/lib/html/includes.js @@ -108,18 +108,8 @@ var MiniProfiler = (function() { // ie is buggy strip out functions var copy = { navigation: {}, - timing: {} + timing: clientPerformance.timing.toJSON() }; - var timing = extend({}, clientPerformance.timing); - - for (p in timing) { - if ( - timing.hasOwnProperty(p) && - !(typeof timing[p] === "function") - ) { - copy.timing[p] = timing[p]; - } - } if (clientPerformance.navigation) { copy.navigation.redirectCount = @@ -147,10 +137,13 @@ var MiniProfiler = (function() { (function() { var request = new XMLHttpRequest(); var url = options.path + "results"; - var params = "id=" - .concat(id, "&clientPerformance=") - .concat(clientPerformance, "&clientProbes=") - .concat(clientProbes, "&popup=1"); + var params = { + id: id, + clientPerformance: clientPerformance, + clientProbes: clientProbes, + popup: 1 + }; + var queryParam = toQueryString(params); request.open("POST", url, true); request.onload = function() { @@ -172,24 +165,45 @@ var MiniProfiler = (function() { "Content-Type", "application/x-www-form-urlencoded" ); - request.send(params); + request.send(queryParam); })(); } } }; - var extend = function extend(out) { - out = out || {}; - - for (var i = 1; i < _arguments.length; i++) { - if (!_arguments[i]) continue; - - for (var key in _arguments[i]) { - if (_arguments[i].hasOwnProperty(key)) out[key] = _arguments[i][key]; + var toQueryString = function toQueryString(data, parentKey) { + var result = []; + for (var key in data) { + var val = data[key]; + var newKey = !parentKey ? key : parentKey + "[" + key + "]"; + if ( + typeof val === "object" && + !Array.isArray(val) && + val !== null && + val !== undefined + ) { + result[result.length] = toQueryString(val, newKey); + } else { + if (Array.isArray(val)) { + val.forEach(function(v) { + result[result.length] = + encodeURIComponent(newKey + "[]") + "=" + encodeURIComponent(v); + }); + } else if (val === null || val === undefined) { + result[result.length] = encodeURIComponent(newKey) + "="; + } else { + result[result.length] = + encodeURIComponent(newKey) + + "=" + + encodeURIComponent(val.toString()); + } } } - - return out; + return result + .filter(function(element) { + return element && element.length > 0; + }) + .join("&"); }; var renderTemplate = function renderTemplate(json) { diff --git a/lib/html/includes.tmpl b/lib/html/includes.tmpl index db68f0ef..14ad9698 100644 --- a/lib/html/includes.tmpl +++ b/lib/html/includes.tmpl @@ -128,8 +128,8 @@ {{? it.custom_link}} {{= it.custom_link_name }} {{?}} - {{? it.has_trivial_timings}} - + {{? it.page.has_trivial_timings}} + show trivial {{?}} diff --git a/lib/html/vendor.js b/lib/html/vendor.js index 609bbb7b..ca8fd349 100644 --- a/lib/html/vendor.js +++ b/lib/html/vendor.js @@ -11,7 +11,7 @@ var out='
share more ';if(it.custom_link){out+=' '+( it.custom_link_name )+' ';}out+=' ';if(it.has_trivial_timings){out+=' show trivial ';}return out; +var out=' share more ';if(it.custom_link){out+=' '+( it.custom_link_name )+' ';}out+=' ';if(it.page.has_trivial_timings){out+=' show trivial ';}return out; } MiniProfiler.templates["timingTemplate"] = function anonymous(it ) { diff --git a/lib/mini_profiler/asset_version.rb b/lib/mini_profiler/asset_version.rb index 05990526..a8ee572a 100644 --- a/lib/mini_profiler/asset_version.rb +++ b/lib/mini_profiler/asset_version.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true module Rack class MiniProfiler - ASSET_VERSION = '67dd1c2571ced7fc74ae7f1813e47bdf' + ASSET_VERSION = '22e813e9a683ebee90a5afa948cffb0b' end end