Throttle the commit info loading.
Dan Brook [Sun, 2 May 2010 14:03:29 +0000 (15:03 +0100)]
So instead of making N calls as soon as the page loads get the
commit info for the next entry as soon as the last one finishes.

root/static/js/site.js

index 7f9265b..3c748fe 100755 (executable)
@@ -1,12 +1,12 @@
 function findPos(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
-       do {
-               curleft += obj.offsetLeft;
-               curtop += obj.offsetTop;
-       } 
-       while (obj = obj.offsetParent);
-       return [curleft,curtop];
+         do {
+                 curleft += obj.offsetLeft;
+                 curtop += obj.offsetTop;
+         } 
+         while (obj = obj.offsetParent);
+         return [curleft,curtop];
        }
 }
 
@@ -58,17 +58,21 @@ function compareDiffs(){
     return false;
 }
 
-function loadCommitInfo() {
-  jQuery('#commit-tree .message').each(function() {
-    var cell     = jQuery(this);
-    var filename = cell.find('.js-data').text();
-    jQuery.getJSON(uriFor('file_commit_info') + '/' + filename, {}, function(commitInfo) {
-      cell.empty();
-      cell.html('<a href="'+uriFor('commit', commitInfo.sha1)+'">'+commitInfo.comment+'</a> '+commitInfo.age);
-    });
+function _loadCommitInfo(cells) {
+  var cell     = jQuery(cells.shift());
+  var filename = cell.find('.js-data').text();
+  jQuery.getJSON(uriFor('file_commit_info') + '/' + filename, {}, function(commitInfo) {
+    cell.empty();
+    cell.html('<a href="'+uriFor('commit', commitInfo.sha1)+'">'+commitInfo.comment+'</a> '+commitInfo.age);
+    if(cells.length > 0)
+      _loadCommitInfo(cells);
   });
 }
 
+function loadCommitInfo() {
+  _loadCommitInfo( jQuery('#commit-tree .message').get() );
+}
+
 jQuery(function() {
     // Provide sub-nav dropdowns (I think).
     startList();