Last active
February 19, 2016 19:54
-
-
Save rsanchez/c03765881664f9d24062 to your computer and use it in GitHub Desktop.
EE slow query log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uses localStorage to keep a running log of all queries on the site | |
// so you can browse through the site and identify the biggest query | |
function EESlowQueryLog() { | |
// get cached queries | |
var queries = localStorage.getItem("EESlowQueryLog") ? JSON.parse(localStorage.getItem("EESlowQueryLog")) : []; | |
function loadQueries() { | |
// loop through all queries | |
$("#ci_profiler_queries_db_1 tr").each(function() { | |
// get this execution time of this query | |
var time = $.trim($(this).find("td:first").text()); | |
// get the query itself | |
var query = ""; | |
// what page you're on | |
var uri = location.pathname; | |
// loop through all the parts of the query | |
$(this).find("td:eq(1) code > span > span").each(function() { | |
// get this part's text | |
var text = $(this).text(); | |
// omit comments | |
if (/^\s?#/.test(text)) { | |
return; | |
} | |
// add part to full query | |
query += text; | |
}); | |
// add to queries array | |
queries.push({ | |
time: time, | |
query: query, | |
uri: uri | |
}); | |
}); | |
sortQueries(); | |
} | |
// sort so slowest queries are on top | |
function sortQueries() { | |
queries.sort(function(a, b) { | |
if (a.time === b.time) { | |
return 0; | |
} | |
return a.time < b.time ? 1 : -1; | |
}); | |
} | |
// save queries to cache | |
function saveQueries() { | |
localStorage.setItem("EESlowQueryLog", JSON.stringify(queries)); | |
} | |
// constructor | |
loadQueries(); | |
saveQueries(); | |
// public methods | |
this.get = function() { | |
return queries; | |
}; | |
this.clear = function() { | |
queries = []; | |
saveQueries(); | |
}; | |
} | |
$(function() { | |
window.eeSlowQueryLog = new EESlowQueryLog(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment