comparison js/modules/app.js @ 72:0eab9a3ff12f

replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
author Atul Varma <avarma@mozilla.com>
date Sun, 25 Apr 2010 18:21:34 -0700
parents 4ec651cc606e
children 1cd66cabe153
comparison
equal deleted inserted replaced
71:4ec651cc606e 72:0eab9a3ff12f
40 40
41 callbacks.forEach(function(cb) { cb(info); }); 41 callbacks.forEach(function(cb) { cb(info); });
42 }; 42 };
43 }; 43 };
44 44
45 Require.modules["app/bugzilla-serial"] = function(exports, require) { 45 Require.modules["app/bugzilla-auth"] = function(exports, require) {
46 const EVENTS = ["abort", "error", "load"];
47
48 var myproto = require("bugzilla"); 46 var myproto = require("bugzilla");
49 var active = null;
50 var queue = [];
51
52 function enqueue(bugzilla, options) {
53 queue.push({bugzilla: bugzilla, options: options});
54 if (!active)
55 activateNextInQueue();
56 }
57
58 function activateNextInQueue() {
59 if (queue.length) {
60 var entry = queue.splice(0, 1)[0];
61 var xhr = myproto.ajax.call(entry.bugzilla, entry.options);
62 EVENTS.forEach(function(name) {
63 xhr.addEventListener(name, onDone, false);
64 });
65 active = xhr;
66 } else
67 active = null;
68 }
69
70 function onDone(event) {
71 var xhr = event.target;
72 EVENTS.forEach(function(name) {
73 xhr.removeEventListener(name, onDone, false);
74 });
75 activateNextInQueue();
76 };
77
78 exports.Bugzilla = {
79 ajax: function ajax(options) {
80 enqueue(this, options);
81 },
82 __proto__: myproto
83 };
84 };
85
86 Require.modules["app/bugzilla-auth"] = function(exports, require) {
87 var myproto = require("app/bugzilla-serial").Bugzilla;
88 47
89 exports.Bugzilla = { 48 exports.Bugzilla = {
90 ajax: function ajax(options) { 49 ajax: function ajax(options) {
91 var user = require("app/login").get(); 50 var user = require("app/login").get();
92 51
422 var $ = require("jQuery"); 381 var $ = require("jQuery");
423 var cache = require("cache"); 382 var cache = require("cache");
424 var dateUtils = require("date-utils"); 383 var dateUtils = require("date-utils");
425 var bugzilla = require("app/bugzilla-auth").Bugzilla; 384 var bugzilla = require("app/bugzilla-auth").Bugzilla;
426 var window = require("window"); 385 var window = require("window");
386 var xhrQueue = require("xhr/queue").create();
427 387
428 function sortByLastChanged(bugs) { 388 function sortByLastChanged(bugs) {
429 var lctimes = {}; 389 var lctimes = {};
430 390
431 bugs.forEach( 391 bugs.forEach(
530 if (cached) 490 if (cached)
531 showBugs($(selector), cached); 491 showBugs($(selector), cached);
532 492
533 $(selector).find("h2").addClass("loading"); 493 $(selector).find("h2").addClass("loading");
534 494
535 bugzilla.search(newTerms, 495 xhrQueue.enqueue(
536 function(response) { 496 function() {
537 cache.set(cacheKey, response.bugs); 497 return bugzilla.search(
538 showBugs($(selector), response.bugs); 498 newTerms,
539 $(selector).find("h2").removeClass("loading"); 499 function(response) {
540 }); 500 cache.set(cacheKey, response.bugs);
501 showBugs($(selector), response.bugs);
502 $(selector).find("h2").removeClass("loading");
503 });
504 });
541 } 505 }
542 506
543 function timeAgo(ms) { 507 function timeAgo(ms) {
544 var now = new Date(); 508 var now = new Date();
545 var then = new Date(now - ms); 509 var then = new Date(now - ms);
553 var defaults = { 517 var defaults = {
554 changed_after: timeAgo(MS_PER_WEEK * 14) 518 changed_after: timeAgo(MS_PER_WEEK * 14)
555 }; 519 };
556 520
557 function update(myUsername) { 521 function update(myUsername) {
522 xhrQueue.clear();
523
558 report("#code-reviews", myUsername, 524 report("#code-reviews", myUsername,
559 {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"], 525 {status: ["NEW", "UNCONFIRMED", "ASSIGNED", "REOPENED"],
560 flag_DOT_requestee: myUsername}); 526 flag_DOT_requestee: myUsername});
561 527
562 report("#assigned-bugs", myUsername, 528 report("#assigned-bugs", myUsername,