Commit 6c338955 authored by Ken Hawkins's avatar Ken Hawkins
Browse files

Optimise render queue function

parent 6ebdee90
...@@ -54,48 +54,44 @@ function requestIsExpired(requestDate) { ...@@ -54,48 +54,44 @@ function requestIsExpired(requestDate) {
var render_queue_time = 1; var render_queue_time = 1;
// Queue up the requests to not exceed GA's requests per second (10 per second, per IP), 50,000 a day // Queue up the requests to not exceed GA's requests per second (10 per second, per IP), 50,000 a day
// https://developers.google.com/analytics/devguides/config/mgmt/v3/limits-quotas#general_api // https://developers.google.com/analytics/devguides/config/mgmt/v3/limits-quotas#general_api
// We pass in:
// - processor = task to be scheduled
// - row = result row to work; 0 = global
function render_queue(processor,row) { function render_queue(processor,row) {
render_queue_time = render_queue_time + 500; // set requests XXms second apart render_queue_time += 500; // set requests XXms second apart
if (processor == "traffic-overview") {
window.setTimeout(function(){ window.setTimeout(function(){
render_query_traffic_overview('.traffic-overview','ga:date,ga:nthDay','ga:uniquePageviews',shared['filters']+'',shared,row); switch (processor) {
},render_queue_time); case 'traffic-overview':
} fetch_traffic_overview('.traffic-overview','ga:date,ga:nthDay','ga:uniquePageviews',
shared['filters']+'',shared,row);
if (processor == "overview-list") { break;
window.setTimeout(function(){ case 'overview-list':
render_query_overview('.top-stories','ga:pageTitle,ga:pagePath','ga:uniquePageviews',shared['filters']+'',shared,row); fetch_overview('.top-stories','ga:pageTitle,ga:pagePath','ga:uniquePageviews',
},render_queue_time); shared['filters']+'',shared,row);
} break;
case 'page-detail':
if (processor == "page-detail") { fetch_page_detail('tr.result-'+row,'ga:fullReferrer','ga:uniquePageviews',
window.setTimeout(function(){
render_query_page_detail('tr.result-'+row,'ga:fullReferrer','ga:uniquePageviews',
'ga:pagePath=='+analyticsResults[row].url,shared,row); 'ga:pagePath=='+analyticsResults[row].url,shared,row);
},render_queue_time); break;
} case 'ui-regions':
if (processor == "ui-regions") { fetch_ui_regions('tr.result-'+row,'ga:eventAction','ga:uniqueEvents',
window.setTimeout(function(){
render_query_ui_regions('tr.result-'+row,'ga:eventAction','ga:uniqueEvents',
'ga:pagePath=='+analyticsResults[row].url,shared,row); 'ga:pagePath=='+analyticsResults[row].url,shared,row);
},render_queue_time); break;
} case 'page-time':
if (processor == "page-time") { fetch_page_time('tr.result-'+row,'ga:pagePath','ga:avgTimeOnPage',
window.setTimeout(function(){
render_query_page_time('tr.result-'+row,'ga:pagePath','ga:avgTimeOnPage',
'ga:pagePath=='+analyticsResults[row].url,shared,row); 'ga:pagePath=='+analyticsResults[row].url,shared,row);
},render_queue_time); case 'leave-rate':
} fetch_leave_rate('tr.result-'+row,'ga:pagePath','ga:bounceRate',
if (processor == "leave-rate") {
window.setTimeout(function(){
render_query_leave_rate('tr.result-'+row,'ga:pagePath','ga:bounceRate',
'ga:pagePath=='+analyticsResults[row].url,shared,row); 'ga:pagePath=='+analyticsResults[row].url,shared,row);
},render_queue_time); break;
default:
console.log('Unexpected queue task: ' + processor);
} }
},render_queue_time);
} }
function render_query_traffic_overview(target,dimensions,metrics,filters,shared) { function fetch_traffic_overview(target,dimensions,metrics,filters,shared) {
$('#table-header').html('Top stories from the past ' + (shared['dayRange']-1) + ' days'); $('#table-header').html('Top stories from the past ' + (shared['dayRange']-1) + ' days');
var now = shared['originDate']; // .subtract(3, 'day'); var now = shared['originDate']; // .subtract(3, 'day');
...@@ -170,7 +166,7 @@ function render_query_traffic_overview(target,dimensions,metrics,filters,shared) ...@@ -170,7 +166,7 @@ function render_query_traffic_overview(target,dimensions,metrics,filters,shared)
} }
function render_query_overview(target,dimensions,metrics,filters,shared) { function fetch_overview(target,dimensions,metrics,filters,shared) {
if (requestIsExpired(shared['originDate'])) { return; } if (requestIsExpired(shared['originDate'])) { return; }
var now = shared['originDate']; // .subtract(3, 'day'); var now = shared['originDate']; // .subtract(3, 'day');
var localQuery = query({ var localQuery = query({
...@@ -223,11 +219,8 @@ function render_query_overview(target,dimensions,metrics,filters,shared) { ...@@ -223,11 +219,8 @@ function render_query_overview(target,dimensions,metrics,filters,shared) {
// now that we no the top stories, we can make queries about them // now that we no the top stories, we can make queries about them
render_queue('page-detail',row); render_queue('page-detail',row);
render_queue('ui-regions',row); render_queue('ui-regions',row);
render_queue('page-time',row); render_queue('page-time',row);
render_queue('leave-rate',row); render_queue('leave-rate',row);
} }
...@@ -250,7 +243,7 @@ function parseReferralName(siteToParse) { ...@@ -250,7 +243,7 @@ function parseReferralName(siteToParse) {
return siteToParse; return siteToParse;
} }
function render_query_page_detail(target,dimensions,metrics,filters,shared,resultPosition) { function fetch_page_detail(target,dimensions,metrics,filters,shared,resultPosition) {
if (requestIsExpired(shared['originDate'])) { return; } if (requestIsExpired(shared['originDate'])) { return; }
var now = shared['originDate']; // .subtract(3, 'day'); var now = shared['originDate']; // .subtract(3, 'day');
var localQuery = query({ var localQuery = query({
...@@ -274,7 +267,7 @@ function render_query_page_detail(target,dimensions,metrics,filters,shared,resul ...@@ -274,7 +267,7 @@ function render_query_page_detail(target,dimensions,metrics,filters,shared,resul
}); });
} }
function render_query_ui_regions(target,dimensions,metrics,filters,shared,resultPosition) { function fetch_ui_regions(target,dimensions,metrics,filters,shared,resultPosition) {
if (requestIsExpired(shared['originDate'])) { return; } if (requestIsExpired(shared['originDate'])) { return; }
var now = shared['originDate']; // .subtract(3, 'day'); var now = shared['originDate']; // .subtract(3, 'day');
var localQuery = query({ var localQuery = query({
...@@ -325,7 +318,7 @@ function render_query_ui_regions(target,dimensions,metrics,filters,shared,result ...@@ -325,7 +318,7 @@ function render_query_ui_regions(target,dimensions,metrics,filters,shared,result
}); });
} }
function render_query_page_time(target,dimensions,metrics,filters,shared,resultPosition) { function fetch_page_time(target,dimensions,metrics,filters,shared,resultPosition) {
if (requestIsExpired(shared['originDate'])) { return; } if (requestIsExpired(shared['originDate'])) { return; }
var now = shared['originDate']; // .subtract(3, 'day'); var now = shared['originDate']; // .subtract(3, 'day');
var localQuery = query({ var localQuery = query({
...@@ -357,7 +350,7 @@ function render_query_page_time(target,dimensions,metrics,filters,shared,resultP ...@@ -357,7 +350,7 @@ function render_query_page_time(target,dimensions,metrics,filters,shared,resultP
}); });
} }
function render_query_leave_rate(target,dimensions,metrics,filters,shared,resultPosition) { function fetch_leave_rate(target,dimensions,metrics,filters,shared,resultPosition) {
if (requestIsExpired(shared['originDate'])) { return; } if (requestIsExpired(shared['originDate'])) { return; }
var now = shared['originDate']; // .subtract(3, 'day'); var now = shared['originDate']; // .subtract(3, 'day');
var localQuery = query({ var localQuery = query({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment