Bug 1502923 - Delay adding and sorting unifinder items until load is complete. r=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 05 Aug 2019 20:01:41 +1200
changeset 27280 f52ba6e5e48ba08eac4adc9556ea58bb056981e2
parent 27279 45b5c5bb3fe6e773da4588e42a93caa4c3cded1a
child 27281 e1a0f9d5e69c995c3e430c99d6eb1aa2e89a7e96
push id16265
push usermozilla@jorgk.com
push dateThu, 08 Aug 2019 09:37:12 +0000
treeherdercomm-central@ca2b75176e39 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspmorris
bugs1502923
Bug 1502923 - Delay adding and sorting unifinder items until load is complete. r=pmorris
calendar/base/content/calendar-unifinder.js
--- a/calendar/base/content/calendar-unifinder.js
+++ b/calendar/base/content/calendar-unifinder.js
@@ -65,30 +65,32 @@ var unifinderObserver = {
     QueryInterface: cal.generateQI([
         Ci.calICompositeObserver,
         Ci.nsIObserver,
         Ci.calIObserver
     ]),
 
     // calIObserver:
     onStartBatch: function() {
+        gUnifinderNeedsRefresh = true;
     },
 
     onEndBatch: function() {
-        refreshEventTree();
     },
 
     onLoad: function() {
-        if (isUnifinderHidden() && !gUnifinderNeedsRefresh) {
+        if (isUnifinderHidden()) {
             // If the unifinder is hidden, all further item operations might
             // produce invalid entries in the unifinder. From now on, ignore
             // those operations and refresh as soon as the unifinder is shown
             // again.
             gUnifinderNeedsRefresh = true;
             unifinderTreeView.clearItems();
+        } else {
+            refreshEventTree();
         }
     },
 
     onAddItem: function(aItem) {
         if (cal.item.isEvent(aItem) &&
             !gUnifinderNeedsRefresh &&
             unifinderTreeView.mFilter.isItemInFilters(aItem)
             ) {
@@ -228,17 +230,16 @@ function prepareCalendarUnifinder() {
         }
     }
 
     unifinderTreeView.ready = true;
 
     // Display something upon first load. onLoad doesn't work properly for
     // observers
     if (!isUnifinderHidden()) {
-        gUnifinderNeedsRefresh = false;
         refreshEventTree();
     }
 }
 
 /**
  * Called when the window is unloaded to clean up any observers and listeners
  * added.
  */
@@ -858,16 +859,18 @@ function refreshEventTree() {
 
     let field = document.getElementById("unifinder-search-field");
     if (field) {
         unifinderTreeView.mFilter.filterText = field.value;
     }
 
     addItemsFromCalendar(cal.view.getCompositeCalendar(window),
                          addItemsFromCompositeCalendarInternal);
+
+    gUnifinderNeedsRefresh = false;
 }
 
 /**
  * EXTENSION_POINTS
  * Filters the passed event array according to the currently applied filter.
  * Afterwards, applies the items to the unifinder view.
  *
  * If you are implementing a new filter, you can overwrite this function and
@@ -959,17 +962,16 @@ function focusSearch() {
  */
 function ensureUnifinderLoaded() {
     if (ensureUnifinderLoaded.done) {
         return;
     }
     ensureUnifinderLoaded.done = true;
 
     if (!isUnifinderHidden() && gUnifinderNeedsRefresh) {
-        gUnifinderNeedsRefresh = false;
         refreshEventTree();
     }
 }
 
 /**
  * Toggles the hidden state of the unifinder.
  */
 function toggleUnifinder() {
@@ -977,17 +979,16 @@ function toggleUnifinder() {
     goToggleToolbar("bottom-events-box", "calendar_show_unifinder_command");
     goToggleToolbar("calendar-view-splitter");
 
     unifinderTreeView.treeElement.view = unifinderTreeView;
 
     // When the unifinder is hidden, refreshEventTree is not called. Make sure
     // the event tree is refreshed now.
     if (!isUnifinderHidden() && gUnifinderNeedsRefresh) {
-        gUnifinderNeedsRefresh = false;
         refreshEventTree();
     }
 
     // Make sure the selection is correct
     if (unifinderTreeView.doingSelection) {
         unifinderTreeView.resetAllowSelection();
     }
     unifinderTreeView.setSelectedItems();