Bug 1612247 - Remove nsIMsgDatabase.nextMatchingHdrs. r=mkmelin DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Fri, 08 May 2020 13:35:06 +0300
changeset 39093 96995bd8f55c685952d95b51fdb1c0a8f10c05a9
parent 39092 e19bac859ee761f16925bbc3775009b65acdac68
child 39094 e5d6fe83becb2b9d1052041cebd8396194ed2f10
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin
bugs1612247
Bug 1612247 - Remove nsIMsgDatabase.nextMatchingHdrs. r=mkmelin DONTBUILD
mailnews/base/content/markByDate.js
mailnews/db/gloda/modules/IndexMsg.jsm
mailnews/db/msgdb/public/nsIMsgDatabase.idl
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/db/msgdb/test/unit/test_filter_enumerator.js
--- a/mailnews/base/content/markByDate.js
+++ b/mailnews/base/content/markByDate.js
@@ -1,15 +1,19 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from dateFormat.js */
 
+const { fixIterator } = ChromeUtils.import(
+  "resource:///modules/iteratorUtils.jsm"
+);
+
 var MILLISECONDS_PER_HOUR = 60 * 60 * 1000;
 var MICROSECONDS_PER_DAY = 1000 * MILLISECONDS_PER_HOUR * 24;
 
 document.addEventListener("dialogaccept", onAccept);
 
 function onLoad() {
   var upperDateBox = document.getElementById("upperDate");
   // focus the upper bound control - this is where we expect most users to enter
@@ -75,18 +79,16 @@ function markInDatabase(lower, upper) {
     messageDatabase = messageFolder.msgDatabase;
   }
 
   if (!messageDatabase) {
     dump("markByDate::markInDatabase: there /is/ no database to operate on!\n");
     return;
   }
 
-  // the headers which are going to be marked
-  let headers = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
   let searchSession = Cc[
     "@mozilla.org/messenger/searchSession;1"
   ].createInstance(Ci.nsIMsgSearchSession);
   let searchTerms = [];
   searchSession.addScopeTerm(Ci.nsMsgSearchScope.offlineMail, messageFolder);
 
   const nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
   const nsMsgSearchOp = Ci.nsMsgSearchOp;
@@ -108,27 +110,14 @@ function markInDatabase(lower, upper) {
     value = searchTerm.value;
     value.attrib = nsMsgSearchAttrib.Date;
     value.date = lower;
     searchTerm.value = value;
     searchTerms.push(searchTerm);
   }
 
   let filterEnumerator = messageDatabase.getFilterEnumerator(searchTerms);
-
-  if (filterEnumerator) {
-    let keepGoing;
-    let numMatches = {};
-    do {
-      keepGoing = messageDatabase.nextMatchingHdrs(
-        filterEnumerator,
-        0,
-        0,
-        headers,
-        numMatches
-      );
-    } while (keepGoing);
-  }
+  let headers = Array.from(fixIterator(filterEnumerator, Ci.nsIMsgDBHdr));
 
   if (headers.length) {
     messageFolder.markMessagesRead(headers, true);
   }
 }
--- a/mailnews/db/gloda/modules/IndexMsg.jsm
+++ b/mailnews/db/gloda/modules/IndexMsg.jsm
@@ -1456,31 +1456,24 @@ var GlodaMsgIndexer = {
     //  We do this in order to be able to report to the user what we're doing.
     // TODO: give up after reaching a certain number of messages in folders
     //  with ridiculous numbers of messages and make the interface just say
     //  something like "over N messages to go."
 
     this._indexerGetEnumerator(enumeratorType);
 
     let numMessagesToIndex = 0;
-    let numMessagesOut = {};
-    // Keep going until we run out of headers.
-    while (
-      this._indexingFolder.msgDatabase.nextMatchingHdrs(
-        this._indexingEnumerator,
-        HEADER_CHECK_SYNC_BLOCK_SIZE * 8, // this way is faster, do more
-        0, // moot, we don't return headers
-        null, // don't return headers, we just want the count
-        numMessagesOut
-      )
-    ) {
-      numMessagesToIndex += numMessagesOut.value;
-      yield this.kWorkSync;
+    // eslint-disable-next-line no-unused-vars
+    for (let ignore of fixIterator(this._indexingEnumerator, Ci.nsIMsgDBHdr)) {
+      // We're only counting, so do bigger chunks on this pass.
+      ++numMessagesToIndex;
+      if (numMessagesToIndex % (HEADER_CHECK_SYNC_BLOCK_SIZE * 8) == 0) {
+        yield this.kWorkSync;
+      }
     }
-    numMessagesToIndex += numMessagesOut.value;
 
     aJob.goal = numMessagesToIndex;
 
     if (numMessagesToIndex > 0) {
       // We used up the iterator, get a new one.
       this._indexerGetEnumerator(enumeratorType);
 
       // Pass 2: index the messages.
--- a/mailnews/db/msgdb/public/nsIMsgDatabase.idl
+++ b/mailnews/db/msgdb/public/nsIMsgDatabase.idl
@@ -22,17 +22,16 @@
  */
 #include "nsISupports.idl"
 #include "nsIDBChangeAnnouncer.idl"
 
 %{C++
 #include "nsTArray.h"
 %}
 
-interface nsIMutableArray;
 interface nsIMsgDatabase;
 interface nsIDBChangeListener;
 interface nsIMsgDBHdr;
 interface nsISimpleEnumerator;
 interface nsIMsgThread;
 interface nsIDBFolderInfo;
 interface nsIMsgOfflineImapOperation;
 interface nsIMsgFolder;
@@ -301,47 +300,26 @@ interface nsIMsgDatabase : nsIDBChangeAn
    */
   void ListAllKeys(in nsIMsgKeyArray array);
 
   nsISimpleEnumerator EnumerateMessages();
   nsISimpleEnumerator ReverseEnumerateMessages();
   nsISimpleEnumerator EnumerateThreads();
 
   /**
-   * Get an enumerator for use with nextMatchingHdrs. The enumerator
-   * will only return messages that match the passed-in search terms.
+   * Get an enumerator got messages matching the passed-in search terms.
    *
    * @param     searchTerms       array of search terms to evaluate.
    * @param     reverse           start at the end, defaults to false.
    *
-   * @returns   an enumerator for passing into nextMatchingHdrs
+   * @returns   an enumerator to iterate over matching messages.
    */
   nsISimpleEnumerator getFilterEnumerator(in Array<nsIMsgSearchTerm> searchTerms,
                                           [optional] in boolean reverse);
 
-  /**
-   * Get the next N matching headers using a filter enumerator
-   * obtained by calling getFilterEnumerator.
-   *
-   * @param     enumerator -      This *must* be a filter enumerator
-   * @param     numHdrsToLookAt   if non 0, the number of hdrs to advance the
-   *                              enumerator before returning.
-   * @param     maxResults        if non 0, the max results to return.
-   * @param     matchingHdrs      if non null, array of matching hdrs.
-   * @param     numMatches        if non null, the number of matching hdrs.
-   *
-   * @returns   false, if done, true if more hdrs to look at.
-   */
-  boolean nextMatchingHdrs(in nsISimpleEnumerator enumerator,
-                           in long numHdrsToLookAt,
-                           in long maxResults,
-                           in nsIMutableArray matchingHdrs,
-                           out long numMatches);
-
-
   // count the total and unread msgs, and adjust global count if needed
   void syncCounts();
 
   nsIMsgThread GetThreadContainingMsgHdr(in nsIMsgDBHdr msgHdr) ;
 
   // helpers for user command functions like delete, mark read, etc.
 
   void MarkHdrRead(in nsIMsgDBHdr msgHdr, in boolean bRead,
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -2700,55 +2700,16 @@ nsMsgDatabase::GetFilterEnumerator(
   nsresult rv = e->InitSearchSession(searchTerms, m_folder);
   NS_ENSURE_SUCCESS(rv, rv);
 
   e.forget(aResult);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgDatabase::NextMatchingHdrs(nsISimpleEnumerator *aEnumerator,
-                                int32_t aNumHdrsToLookAt, int32_t aMaxResults,
-                                nsIMutableArray *aMatchingHdrs,
-                                int32_t *aNumMatches, bool *aResult) {
-  NS_ENSURE_ARG_POINTER(aEnumerator);
-  NS_ENSURE_ARG_POINTER(aResult);
-  nsMsgFilteredDBEnumerator *enumerator =
-      static_cast<nsMsgFilteredDBEnumerator *>(aEnumerator);
-
-  // Force mRowPos to be initialized.
-  if (!enumerator->mRowCursor) enumerator->GetRowCursor();
-
-  if (aNumHdrsToLookAt) {
-    enumerator->mStopPos = enumerator->mIterateForwards
-                               ? enumerator->mRowPos + aNumHdrsToLookAt
-                               : enumerator->mRowPos - aNumHdrsToLookAt;
-    if (enumerator->mStopPos < 0) enumerator->mStopPos = 0;
-  }
-  int32_t numMatches = 0;
-  nsresult rv;
-  do {
-    nsCOMPtr<nsISupports> supports;
-    rv = enumerator->GetNext(getter_AddRefs(supports));
-    nsCOMPtr<nsIMsgDBHdr> nextMessage = do_QueryInterface(supports);
-    if (NS_SUCCEEDED(rv) && nextMessage) {
-      if (aMatchingHdrs) aMatchingHdrs->AppendElement(nextMessage);
-      ++numMatches;
-      if (aMaxResults && numMatches == aMaxResults) break;
-    } else
-      break;
-  } while (true);
-
-  if (aNumMatches) *aNumMatches = numMatches;
-
-  *aResult = !enumerator->mDone;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsMsgDatabase::SyncCounts() {
   nsCOMPtr<nsISimpleEnumerator> hdrs;
   nsresult rv = EnumerateMessages(getter_AddRefs(hdrs));
   if (NS_FAILED(rv)) return rv;
   bool hasMore = false;
 
   mdb_count numHdrsInTable = 0;
   int32_t numUnread = 0;
--- a/mailnews/db/msgdb/test/unit/test_filter_enumerator.js
+++ b/mailnews/db/msgdb/test/unit/test_filter_enumerator.js
@@ -1,11 +1,15 @@
 /* import-globals-from ../../../../test/resources/MessageGenerator.jsm */
 load("../../../../resources/MessageGenerator.jsm");
 
+const { fixIterator } = ChromeUtils.import(
+  "resource:///modules/iteratorUtils.jsm"
+);
+
 var gMessages = [];
 
 const kSetCount = 13;
 const kNumExpectedMatches = 10;
 
 function setupGlobals() {
   localAccountUtils.loadLocalMailAccount();
   // Create a message generator
@@ -78,59 +82,23 @@ function run_test() {
   searchTerm.op = Ci.nsMsgSearchOp.IsEmpty;
   value = searchTerm.value;
   value.str = "gloda-id";
   value.attrib = Ci.nsMsgSearchAttrib.HdrProperty;
   searchTerm.value = value;
   searchTerms.push(searchTerm);
 
   let filterEnumerator = inboxDB.getFilterEnumerator(searchTerms);
-  let numMatches = {};
-  let keepGoing = inboxDB.nextMatchingHdrs(
-    filterEnumerator,
-    100,
-    100,
-    null,
-    numMatches
-  );
-  Assert.equal(kNumExpectedMatches, numMatches.value);
-  Assert.ok(!keepGoing);
-  filterEnumerator = inboxDB.getFilterEnumerator(searchTerms);
-  let matchingHdrs = Cc["@mozilla.org/array;1"].createInstance(
-    Ci.nsIMutableArray
-  );
-  do {
-    keepGoing = inboxDB.nextMatchingHdrs(
-      filterEnumerator,
-      5,
-      5,
-      matchingHdrs,
-      numMatches
-    );
-  } while (keepGoing);
+  let matchingHdrs = Array.from(fixIterator(filterEnumerator, Ci.nsIMsgDBHdr));
   Assert.equal(kNumExpectedMatches, matchingHdrs.length);
-  let firstMatch = matchingHdrs.queryElementAt(0, Ci.nsIMsgDBHdr);
-  Assert.equal(firstMatch.messageId, gMessages[1].messageId);
-  let secondMatch = matchingHdrs.queryElementAt(1, Ci.nsIMsgDBHdr);
-  Assert.equal(secondMatch.messageId, gMessages[3].messageId);
+  Assert.equal(matchingHdrs[0].messageId, gMessages[1].messageId);
+  Assert.equal(matchingHdrs[1].messageId, gMessages[3].messageId);
 
   // try it backwards, with roller skates:
   filterEnumerator = inboxDB.getFilterEnumerator(searchTerms, true);
-  matchingHdrs.clear();
-  do {
-    keepGoing = inboxDB.nextMatchingHdrs(
-      filterEnumerator,
-      5,
-      5,
-      matchingHdrs,
-      numMatches
-    );
-  } while (keepGoing);
+  matchingHdrs = Array.from(fixIterator(filterEnumerator, Ci.nsIMsgDBHdr));
   Assert.equal(kNumExpectedMatches, matchingHdrs.length);
-  firstMatch = matchingHdrs.queryElementAt(0, Ci.nsIMsgDBHdr);
-  Assert.equal(firstMatch.messageId, gMessages[12].messageId);
-  secondMatch = matchingHdrs.queryElementAt(1, Ci.nsIMsgDBHdr);
-  Assert.equal(secondMatch.messageId, gMessages[11].messageId);
-  let tenthMatch = matchingHdrs.queryElementAt(9, Ci.nsIMsgDBHdr);
-  Assert.equal(tenthMatch.messageId, gMessages[1].messageId);
+  Assert.equal(matchingHdrs[0].messageId, gMessages[12].messageId);
+  Assert.equal(matchingHdrs[1].messageId, gMessages[11].messageId);
+  Assert.equal(matchingHdrs[9].messageId, gMessages[1].messageId);
 
   do_test_finished();
 }