Bug 867043 - Don't ask for more contacts more than once for the same chunk. r=reuben
authorGregor Wagner <anygregor@gmail.com>
Fri, 03 May 2013 09:15:55 -0700
changeset 130790 08c582b1c486e9982fb3fc3023e77658da36a6cf
parent 130789 d49804cd69d776479edd3ac105a0987f73fa5b31
child 130791 5140723575f55f434cf237aa1161159317a246da
push id1579
push userphilringnalda@gmail.com
push dateSat, 04 May 2013 04:38:04 +0000
treeherderfx-team@a56432a42a41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersreuben
bugs867043
milestone23.0a1
Bug 867043 - Don't ask for more contacts more than once for the same chunk. r=reuben
dom/contacts/ContactManager.js
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -466,16 +466,19 @@ ContactManager.prototype = {
         }
         let result = contacts ? this._convertContacts(contacts) : [null];
         if (data.waitingForNext) {
           if (DEBUG) debug("cursor waiting for contact, sending");
           data.waitingForNext = false;
           let contact = result.shift();
           this._pushArray(data.cachedContacts, result);
           this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact));
+          if (!contact) {
+            this.removeRequest(msg.cursorId);
+          }
         } else {
           if (DEBUG) debug("cursor not waiting, saving");
           this._pushArray(data.cachedContacts, result);
         }
         break;
       case "Contact:Save:Return:OK":
       case "Contacts:Clear:Return:OK":
       case "Contact:Remove:Return:OK":
@@ -675,17 +678,19 @@ ContactManager.prototype = {
 
   handleContinue: function CM_handleContinue(aCursorId) {
     if (DEBUG) debug("handleContinue: " + aCursorId);
     let data = this.getRequest(aCursorId);
     if (data.cachedContacts.length > 0) {
       if (DEBUG) debug("contact in cache");
       let contact = data.cachedContacts.shift();
       this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact));
-      if (data.cachedContacts.length < CONTACTS_SENDMORE_MINIMUM) {
+      if (!contact) {
+        this.removeRequest(aCursorId);
+      } else if (data.cachedContacts.length === CONTACTS_SENDMORE_MINIMUM) {
         cpmm.sendAsyncMessage("Contacts:GetAll:SendNow", { cursorId: aCursorId });
       }
     } else {
       if (DEBUG) debug("waiting for contact");
       data.waitingForNext = true;
     }
   },