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(){ switch (processor) {
render_query_traffic_overview('.traffic-overview','ga:date,ga:nthDay','ga:uniquePageviews',shared['filters']+'',shared,row); case 'traffic-overview':
},render_queue_time); fetch_traffic_overview('.traffic-overview','ga:date,ga:nthDay','ga:uniquePageviews',
} shared['filters']+'',shared,row);
break;
if (processor == "overview-list") { case 'overview-list':
window.setTimeout(function(){ fetch_overview('.top-stories','ga:pageTitle,ga:pagePath','ga:uniquePageviews',
render_query_overview('.top-stories','ga:pageTitle,ga:pagePath','ga:uniquePageviews',shared['filters']+'',shared,row); shared['filters']+'',shared,row);
},render_queue_time); break;
} case 'page-detail':
fetch_page_detail('tr.result-'+row,'ga:fullReferrer','ga:uniquePageviews',
if (processor == "page-detail") { 'ga:pagePath=='+analyticsResults[row].url,shared,row);
window.setTimeout(function(){ break;
render_query_page_detail('tr.result-'+row,'ga:fullReferrer','ga:uniquePageviews', case 'ui-regions':
'ga:pagePath=='+analyticsResults[row].url,shared,row); fetch_ui_regions('tr.result-'+row,'ga:eventAction','ga:uniqueEvents',
},render_queue_time); 'ga:pagePath=='+analyticsResults[row].url,shared,row);
} break;
if (processor == "ui-regions") { case 'page-time':
window.setTimeout(function(){ fetch_page_time('tr.result-'+row,'ga:pagePath','ga:avgTimeOnPage',
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); case 'leave-rate':
},render_queue_time); fetch_leave_rate('tr.result-'+row,'ga:pagePath','ga:bounceRate',
} 'ga:pagePath=='+analyticsResults[row].url,shared,row);
if (processor == "page-time") { break;
window.setTimeout(function(){ default:
render_query_page_time('tr.result-'+row,'ga:pagePath','ga:avgTimeOnPage', console.log('Unexpected queue task: ' + processor);
'ga:pagePath=='+analyticsResults[row].url,shared,row); }
},render_queue_time); },render_queue_time);
}
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);
},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