[perf-web] Properly compute what data we'll be returned from an API call



commit 8a110d13615be9a484e70bc20afed71dc636c1b3
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sun Jun 29 11:02:28 2014 -0400

    Properly compute what data we'll be returned from an API call
    
    To make sure that we don't request the same data twice, pass
    in inclusive date ranges to the API and properly account for
    rounding.

 static/main.js |   53 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/static/main.js b/static/main.js
index 7f24912..7d6d562 100644
--- a/static/main.js
+++ b/static/main.js
@@ -842,8 +842,7 @@ var TIME_OFFSETS = {
     'month': 15.2 * 24 * 60 * 60
 }
 
-function formatDay(seconds) {
-    var date = new Date(seconds * 1000);
+function formatDay(date) {
     return date.getUTCFullYear() + '-' + pad(date.getUTCMonth() + 1) + '-' + pad(date.getUTCDate());
 }
 
@@ -884,7 +883,38 @@ PerfDisplay.prototype.load = function() {
         }
     }
 
-    var url = '/api/values?start=' + formatDay(startSeconds) + '&end=' + formatDay(endSeconds) + '&group=' + 
group;
+    // API is day => day, inclusive, and retrieves all summaries that
+    // overlap that range of days; we round our retrieved range to
+    // summary boundaries so that the "all overlapping" doesn't
+    // affect the retrieved range
+
+    // Find the half-open day range
+    var startDate = new Date(startSeconds * 1000);
+    TIME_OPS['day'].truncate(startDate);
+    var endDate = new Date(endSeconds * 1000);
+    TIME_OPS['day'].truncate(endDate);
+    if (endDate.getTime() != endSeconds * 1000)
+        TIME_OPS['day'].next(endDate);
+
+    if (startDate.getTime() == endDate.getTime()) // Empty day range
+        return;
+
+    // Round to summary boundaries
+    if (group != 'none') {
+        TIME_OPS[group].truncate(startDate);
+        var tmp = endDate.getTime();
+        TIME_OPS[group].truncate(endDate);
+        if (tmp != endDate.getTime())
+            TIME_OPS[group].next(endDate);
+    }
+
+    startSeconds = startDate.getTime() / 1000;
+    endSeconds = endDate.getTime() / 1000;
+
+    // Now make the day-range closed, as the API requires
+    endDate.setTime(endDate.getTime() - DAY_MSECS);
+
+    var url = '/api/values?start=' + formatDay(startDate) + '&end=' + formatDay(endDate) + '&group=' + group;
     if (this.target != null)
         url += '&target=' + encodeURIComponent(this.target);
     if (this.metric != null)
@@ -893,23 +923,6 @@ PerfDisplay.prototype.load = function() {
               function(data) {
                   var timeOffset = TIME_OFFSETS[group];
 
-                  var startDate = new Date(startSeconds * 1000);
-                  TIME_OPS['day'].truncate(startDate);
-                  var endDate = new Date(endSeconds * 1000);
-                  TIME_OPS['day'].truncate(endDate);
-                  TIME_OPS['day'].next(endDate);
-
-                  if (group != 'none') {
-                      TIME_OPS[group].truncate(startDate);
-                      var tmp = endDate.getTime();
-                      TIME_OPS[group].truncate(endDate);
-                      if (tmp != endDate.getTime())
-                          TIME_OPS[group].next(endDate);
-                  }
-
-                  startSeconds = startDate.getTime() / 1000;
-                  endSeconds = endDate.getTime() / 1000;
-
                   if (group != this.loadedGroup) {
                       this.data = {};
                       this.loadedStartSeconds = startSeconds;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]