build.webkit.org/dashboard: Further improve Trac loading
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 24 Aug 2014 01:35:16 +0000 (01:35 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 24 Aug 2014 01:35:16 +0000 (01:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136174

Reviewed by Timothy Hatcher.

* BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js:
(Trac.prototype._xmlTimelineURL): Passing -1 as "max" resulted in an off by one
error, the oldest commit within the range wasn't returned. The correct argument for
"no limit" is 0.
(Trac.prototype.load): Added a function to load a specific time range.
(Trac.prototype._loaded): Updated to support loading revisions that are arbitrarily
positioned with regards to ones that were already known.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172892 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js
Tools/ChangeLog

index 4aac4db..3a5b6dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -44,7 +44,8 @@ Trac.NeedsAuthentication = "needsAuthentication";
 Trac.UpdateInterval = 45000; // 45 seconds
 
 Trac.Event = {
-    CommitsUpdated: "commits-updated"
+    CommitsUpdated: "commits-updated",
+    Loaded: "loaded"
 };
 
 Trac.prototype = {
@@ -78,7 +79,7 @@ Trac.prototype = {
         var fromDay = new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate());
         var toDay = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate());
 
-        return this.baseURL + "timeline?changeset=on&format=rss&max=-1" +
+        return this.baseURL + "timeline?changeset=on&format=rss&max=0" +
             "&from=" +  (toDay.getMonth() + 1) + "%2F" + toDay.getDate() + "%2F" + (toDay.getFullYear() % 100) +
             "&daysback=" + ((toDay - fromDay) / 1000 / 60 / 60 / 24);
     },
@@ -126,59 +127,44 @@ Trac.prototype = {
 
     _loaded: function(dataDocument)
     {
-        var earliestKnownRevision = 0;
-        var latestKnownRevision = 0;
-        if (this.recordedCommits.length) {
-            earliestKnownRevision = this.recordedCommits[0].revisionNumber;
-            latestKnownRevision = this.recordedCommits[this.recordedCommits.length - 1].revisionNumber;
-        }
+        var recordedRevisionNumbers = this.recordedCommits.reduce(function(previousResult, commit) {
+            previousResult[commit.revisionNumber] = commit;
+            return previousResult;
+        }, {});
 
         var knownCommitsWereUpdated = false;
         var newCommits = [];
-        var newCommitsBeforeEarliestKnownRevision = [];
 
         var commitInfoElements = dataDocument.evaluate("/rss/channel/item", dataDocument, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE);
-        var commitInfoElement = undefined;
-        var indexInRecordedCommits = undefined;
+        var commitInfoElement;
         while (commitInfoElement = commitInfoElements.iterateNext()) {
             var commit = this._convertCommitInfoElementToObject(dataDocument, commitInfoElement);
-            if (commit.revisionNumber > latestKnownRevision) {
-                console.assert(typeof indexInRecordedCommits === "undefined");
-                newCommits.push(commit);
-            } else if (commit.revisionNumber < earliestKnownRevision) {
-                console.assert(typeof indexInRecordedCommits === "undefined" || indexInRecordedCommits === -1);
-                newCommitsBeforeEarliestKnownRevision.push(commit);
-            } else {
-                if (typeof indexInRecordedCommits === "undefined") {
-                    // We could have started anywhere in the recorded commits array, let's find where.
-                    // With periodic updates, this will be the latest recorded commit, so starting from the end.
-                    for (var i = this.recordedCommits.length - 1; i >= 0; --i) {
-                        if (this.recordedCommits[i].revisionNumber === commit.revisionNumber) {
-                            indexInRecordedCommits = i;
-                            break;
-                        }
-                    }
-                }
-
-                console.assert(indexInRecordedCommits >= 0);
-                console.assert(this.recordedCommits[indexInRecordedCommits].revisionNumber === commit.revisionNumber);
-
+            if (commit.revisionNumber in recordedRevisionNumbers) {
                 // Author could have changed, as commit queue replaces it after the fact.
-                if (this.recordedCommits[indexInRecordedCommits].author !== commit.author) {
-                    this.recordedCommits[indexInRecordedCommits].author = commit.author;
+                console.assert(recordedRevisionNumbers[commit.revisionNumber].revisionNumber === commit.revisionNumber);
+                if (recordedRevisionNumbers[commit.revisionNumber].author != commit.author) {
+                    recordedRevisionNumbers[commit.revisionNumber].author = commit.author;
                     knownCommitWasUpdated = true;
                 }
-                --indexInRecordedCommits;
-            }
+            } else
+                newCommits.push(commit);
         }
 
-        if (newCommits.length || newCommitsBeforeEarliestKnownRevision.length)
-            this.recordedCommits = newCommitsBeforeEarliestKnownRevision.reverse().concat(this.recordedCommits, newCommits.reverse());
+        if (newCommits.length)
+            this.recordedCommits = newCommits.concat(this.recordedCommits).sort(function(a, b) { return a.revisionNumber - b.revisionNumber; });
 
-        if (newCommits.length || newCommitsBeforeEarliestKnownRevision.length || knownCommitsWereUpdated)
+        if (newCommits.length || knownCommitsWereUpdated)
             this.dispatchEventToListeners(Trac.Event.CommitsUpdated, null);
     },
 
+    load: function(fromDate, toDate)
+    {
+        loadXML(this._xmlTimelineURL(fromDate, toDate), function(dataDocument) {
+            this._loaded(dataDocument);
+            this.dispatchEventToListeners(Trac.Event.Loaded, [fromDate, toDate]);
+        }.bind(this), this._needsAuthentication ? { withCredentials: true } : {});
+    },
+
     update: function()
     {
         loadXML(this._xmlTimelineURL(), this._loaded.bind(this), this._needsAuthentication ? { withCredentials: true } : {});
index 515d453..1a284b1 100644 (file)
@@ -1,5 +1,20 @@
 2014-08-23  Alexey Proskuryakov  <ap@apple.com>
 
+        build.webkit.org/dashboard: Further improve Trac loading
+        https://bugs.webkit.org/show_bug.cgi?id=136174
+
+        Reviewed by Timothy Hatcher.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js:
+        (Trac.prototype._xmlTimelineURL): Passing -1 as "max" resulted in an off by one
+        error, the oldest commit within the range wasn't returned. The correct argument for
+        "no limit" is 0.
+        (Trac.prototype.load): Added a function to load a specific time range.
+        (Trac.prototype._loaded): Updated to support loading revisions that are arbitrarily
+        positioned with regards to ones that were already known.
+
+2014-08-23  Alexey Proskuryakov  <ap@apple.com>
+
         build.webkit.org/dashboard: Make it possible to pull historic data from Buildbot
         https://bugs.webkit.org/show_bug.cgi?id=136182