Fix bug 502936 - cached calendars should not be refreshed at launch/startup time. r=philipp,a=philipp CLOSED TREE
authorMohit Kanwal <mohit.kanwal@gmail.com>
Tue, 20 Sep 2011 08:51:00 +0200
changeset 8486 347508f378fd3cb39057313b3beb2563077cb75b
parent 8485 11c4cb2ed3360e53ae604bdb73d424de8cb921fd
child 8487 5a8ac3d61bc56ebca4cebcde87aad0717e3c29bf
push id147
push usermozilla@kewis.ch
push dateWed, 21 Sep 2011 06:41:38 +0000
treeherdercomm-beta@347508f378fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp, philipp
bugs502936
Fix bug 502936 - cached calendars should not be refreshed at launch/startup time. r=philipp,a=philipp CLOSED TREE
calendar/base/content/agenda-listbox.js
calendar/base/content/calendar-base-view.xml
calendar/base/content/calendar-month-view.xml
calendar/base/content/calendar-multiday-view.xml
calendar/base/content/calendar-task-tree.xml
calendar/base/content/calendar-unifinder.js
calendar/base/content/widgets/minimonth.xml
--- a/calendar/base/content/agenda-listbox.js
+++ b/calendar/base/content/agenda-listbox.js
@@ -627,20 +627,17 @@ function setupContextMenu(popup) {
  *
  * @param aStart        (optional) The start date for the item query.
  * @param aEnd          (optional) The end date for the item query.
  * @param aCalendar     (optional) If specified, the single calendar from
  *                                   which the refresh will occur.
  */
 agendaListbox.refreshCalendarQuery =
 function refreshCalendarQuery(aStart, aEnd, aCalendar) {
-    if (this.mBatchCount > 0) {
-        return;
-    }
-    var pendingRefresh = this.pendingRefresh;
+    let pendingRefresh = this.pendingRefresh;
     if (pendingRefresh) {
         if (calInstanceOf(pendingRefresh, Components.interfaces.calIOperation)) {
             this.pendingRefresh = null;
             pendingRefresh.cancel(null);
         } else {
             return;
         }
     }
@@ -900,38 +897,29 @@ function agenda_QI(aIID) {
         !aIID.equals(Components.interfaces.nsISupports)) {
         throw Components.results.NS_ERROR_NO_INTERFACE;
     }
     return this;
 };
 
 // calIObserver:
 agendaListbox.calendarObserver.onStartBatch = function agenda_onBatchStart() {
-    this.mBatchCount++;
 };
 
 agendaListbox.calendarObserver.onEndBatch =
 function() {
-    this.mBatchCount--;
-    if (this.mBatchCount == 0) {
-        // Rebuild everything
-        this.agendaListbox.refreshCalendarQuery();
-    }
 };
 
 agendaListbox.calendarObserver.onLoad = function() {
     this.agendaListbox.refreshCalendarQuery();
 };
 
 agendaListbox.calendarObserver.onAddItem =
 function observer_onAddItem(item)
 {
-  if (this.mBatchCount) {
-      return;
-  }
   if (!isEvent(item)) {
       return;
   }
 // get all sub items if it is a recurring item
   var occs = this.getOccurrencesBetween(item);
   occs.forEach(this.agendaListbox.addItem, this.agendaListbox);
   setCurrentEvent();
 };
@@ -949,19 +937,16 @@ function getOccurrencesBetween(aItem) {
 
 agendaListbox.calendarObserver.onDeleteItem =
 function observer_onDeleteItem(item, rebuildFlag) {
     this.onLocalDeleteItem(item, true);
 };
 
 agendaListbox.calendarObserver.onLocalDeleteItem =
 function observer_onLocalDeleteItem(item, moveSelection) {
-    if (this.mBatchCount) {
-      return false;
-    }
     if (!isEvent(item)) {
         return false;
     }
     var selectedItemHashId = -1;
 // get all sub items if it is a recurring item
     var occs = this.getOccurrencesBetween(item);
     for (var i = 0; i < occs.length; i++) {
         var isSelected = this.agendaListbox.deleteItem(occs[i], moveSelection);
@@ -969,19 +954,16 @@ function observer_onLocalDeleteItem(item
             selectedItemHashId = occs[i].hashId;
         }
     }
     return selectedItemHashId;
 };
 
 agendaListbox.calendarObserver.onModifyItem =
 function observer_onModifyItem(newItem, oldItem) {
-    if (this.mBatchCount) {
-        return;
-    }
     var selectedItemHashId = this.onLocalDeleteItem(oldItem, false);
     if (!isEvent(newItem)) {
         return;
     }
     this.onAddItem(newItem);
     if (selectedItemHashId != -1) {
         var listItem = agendaListbox.getListItemByHashId(selectedItemHashId);
         if (listItem) {
--- a/calendar/base/content/calendar-base-view.xml
+++ b/calendar/base/content/calendar-base-view.xml
@@ -60,17 +60,16 @@
       <field name="mEndDate">null</field>
       <field name="mTasksInView">false</field>
       <field name="mShowCompleted">false</field>
       <field name="mDisplayDaysOff">true</field>
       <field name="mDaysOffArray">[0,6]</field>
       <field name="mTimezone">null</field>
       <field name="mFlashingEvents">new Object()</field>
       <field name="mSelectedItems">[]</field>
-      <field name="mBatchCount">0</field>
       <field name="mLongWeekdayTotalPixels">-1</field>
       <field name="mResizeHandler">null</field>
       <field name="mDropShadowsLength">null</field>
       <field name="mShadowOffset">null</field>
       <field name="mDropShadows">null</field>
       <field name="mPrefObserver"><![CDATA[
       ({ calView: this,
          observe: function calViewPrefChange(subj, topic, pref) {
@@ -122,33 +121,25 @@
                                      Components.interfaces.calIAlarmServiceObserver,
                                      Components.interfaces.calICompositeObserver,
                                      Components.interfaces.nsISupports]);
             },
 
             calView: this,
 
             onStartBatch: function onStartBatch() {
-                this.calView.mBatchCount++;
             },
             onEndBatch: function onEndBatch() {
-                this.calView.mBatchCount--;
-                if (this.calView.mBatchCount == 0) {
-                    this.calView.refresh();
-                }
             },
 
             onLoad: function onLoad() {
                 this.calView.refresh();
             },
 
             onAddItem: function onAddItem(aItem) {
-                if (this.calView.mBatchCount) {
-                    return;
-                }
 
                 if (isToDo(aItem)) {
                     if (!aItem.entryDate || !aItem.dueDate) {
                         return;
                     }
                     if(!this.calView.mTasksInView){
                         return;
                     }
@@ -162,19 +153,16 @@
                                                        {});
                 for each (let occ in occs) {
                     this.calView.doAddItem(occ);
                 }
                 return;
             },
 
             onModifyItem: function onModifyItem(aNewItem, aOldItem) {
-                if (this.calView.mBatchCount) {
-                    return;
-                }
 
                 if (isToDo(aNewItem) && isToDo(aOldItem) &&
                     !this.calView.mTasksInView) {
                     return;
                 }
                 let occs;
 
                 if (!isToDo(aOldItem) ||
@@ -199,19 +187,16 @@
                                                       this.calView.queryEndDate,
                                                       {});
                 for each (let occ in occs) {
                     this.calView.doAddItem(occ);
                 }
             },
 
             onDeleteItem: function onDeleteItem(aItem) {
-                if (this.calView.mBatchCount) {
-                    return;
-                }
 
                 if (isToDo(aItem)) {
                     if (!this.calView.mTasksInView) {
                         return;
                     }
                     if (!aItem.entryDate || !aItem.dueDate) {
                         return;
                     }
@@ -558,17 +543,17 @@
       <method name="isVisible">
         <body><![CDATA[
             return (this.nodeName == currentView().nodeName);
         ]]></body>
       </method>
 
       <method name="refresh">
         <body><![CDATA[
-          if (this.mBatchCount == 0 && this.isVisible()) {
+          if (this.isVisible()) {
               var refreshJob = {};
               this.mRefreshQueue.push(refreshJob);
               this.popRefreshQueue();
           }
         ]]></body>
       </method>
 
       <method name="addItemsFromCalendar">
--- a/calendar/base/content/calendar-month-view.xml
+++ b/calendar/base/content/calendar-month-view.xml
@@ -662,17 +662,17 @@
       </method>
 
       <method name="setDateRange">
         <parameter name="aStartDate"/>
         <parameter name="aEndDate"/>
         <body><![CDATA[
           this.rangeStartDate = aStartDate;
           this.rangeEndDate = aEndDate;
-          this.mStartDate = getWeekInfoService().getStartOfWeek(aStartDate.getInTimezone(this.mTimezone))
+          this.mStartDate = getWeekInfoService().getStartOfWeek(aStartDate.getInTimezone(this.mTimezone));
           this.mEndDate = getWeekInfoService().getEndOfWeek(aEndDate.getInTimezone(this.mTimezone));
           this.refresh();
 
           // Update the navigation bar.
           cal.navigationBar.setDateRange(aStartDate, aEndDate);
         ]]></body>
       </method>
 
@@ -981,23 +981,21 @@
               this.fireEvent("itemselect", this.mSelectedItems);
           }
         ]]></body>
       </method>
 
       <method name="deleteItemsFromCalendar">
         <parameter name="aCalendar"/>
         <body><![CDATA[
-          let deleteHash = {};
           for each (let box in this.mDateBoxes) {
             for each (let node in box.mItemHash) {
               let item = node.item;
-              if (!deleteHash[item.hashId] && item.calendar.id == aCalendar.id) {
-                deleteHash[item.hashId] = true;
-                this.doDeleteItem(item);
+              if (item.calendar.id == aCalendar.id) {
+                box.deleteItem(item);
               }
             }
           }
         ]]></body>
       </method>
 
       <method name="flashAlarm">
         <parameter name="aAlarmItem"/>
--- a/calendar/base/content/calendar-multiday-view.xml
+++ b/calendar/base/content/calendar-multiday-view.xml
@@ -2487,17 +2487,16 @@
           self.adjustWeekdayLength(self.getAttribute("orient") == "horizontal");
         ]]></body>
       </method>
 
       <!-- mDateList will always be sorted before being set -->
       <field name="mDateList">null</field>
       <!-- array of { date: calIDatetime, column: colbox, header: hdrbox }  -->
       <field name="mDateColumns">null</field>
-      <field name="mBatchCount">0</field>
       <field name="mPixPerMin">0.6</field>
       <field name="mMinPixelsPerMinute">0.1</field>
       <field name="mSelectedDayCol">null</field>
       <field name="mSelectedDay">null</field>
       <field name="mStartMin">0*60</field>
       <field name="mEndMin">24*60</field>
       <field name="mDayStartMin">0</field>
       <field name="mDayEndMin">0</field>
@@ -3414,25 +3413,23 @@
 
           this.adjustScrollbarSpacersForAlldayEvents(aEvent);
         ]]></body>
       </method>
 
       <method name="deleteItemsFromCalendar">
         <parameter name="aCalendar"/>
         <body><![CDATA[
-          let deleteHash = {};
           for each (let col in this.mDateColumns) {
               // get all-day events in column header and events within the column
               let colEvents = [ box.occurrence for each (box in col.header.mItemBoxes) ]
                               .concat([ info.event for each (info in col.column.mEventInfos) ]);
 
               for each (let event in colEvents) {
-                  if (!(event.hashId in deleteHash) && event.calendar.id == aCalendar.id) {
-                      deleteHash[event.hashId] = true;
+                  if (event.calendar.id == aCalendar.id) {
                       this.doDeleteItem(event);
                   }
               }
           }
         ]]></body>
       </method>
 
       <method name="adjustScrollBarSpacers">
--- a/calendar/base/content/calendar-task-tree.xml
+++ b/calendar/base/content/calendar-task-tree.xml
@@ -815,48 +815,38 @@
 
       <!--
         Observer for the calendar event data source. This keeps the unifinder
         display up to date when the calendar event data is changed
         -->
       <field name="mTaskTreeObserver"><![CDATA[
       ({
           binding: this,
-          mBatchCount: 0,
 
           QueryInterface: function tTO_QueryInterface(aIID) {
               return doQueryInterface(this, null, aIID,
                                       [Components.interfaces.calICompositeObserver,
                                        Components.interfaces.calIObserver]);
           },
 
          /**
            * calIObserver methods and properties
            */
           onStartBatch: function tTO_onStartBatch() {
-              this.mBatchCount++;
           },
 
           onEndBatch: function tTO_onEndBatch() {
-              this.mBatchCount--;
-              if (this.mBatchCount == 0) {
-                  this.binding.refresh();
-              }
           },
 
           onLoad: function tTO_onLoad() {
-              if (this.mBatchCount == 0) {
-                  this.binding.refresh();
-              }
+              this.binding.refresh();
           },
 
           onAddItem: function tTO_onAddItem(aItem) {
-              if (cal.isToDo(aItem) &&
-                  !this.mBatchCount) { 
-
+              if (cal.isToDo(aItem)) {
                   // get occurrences of repeating items
                   let occs;
                   if (this.binding.mFilter.endDate) {
                       occs = aItem.getOccurrencesBetween(this.binding.mFilter.startDate,
                                                          this.binding.mFilter.endDate,
                                                          {});
                   } else {
                       occs = [aItem];
@@ -865,18 +855,17 @@
                       if (this.binding.mFilter.isItemInFilters(occ)) {
                           this.binding.mTreeView.addItem(occ);
                       }
                   }
               }
           },
 
           onModifyItem: function tTO_onModifyItem(aNewItem, aOldItem) {
-              if ((cal.isToDo(aNewItem) || cal.isToDo(aOldItem))
-                  && !this.mBatchCount) {
+              if ((cal.isToDo(aNewItem) || cal.isToDo(aOldItem))) {
 
                   if ((this.binding.mFilter.endDate) &&
                       (aOldItem.recurrenceInfo || aNewItem.recurrenceInfo)) {
 
                       // if item is repeating refresh to updated all modified occurrences
                       this.binding.refresh();
                   } else {
                       // forward the call to the view which will in turn
@@ -887,17 +876,17 @@
                   // we also need to notify potential listeners.
                   var event = document.createEvent('Events');
                   event.initEvent('select', true, false);
                   this.binding.dispatchEvent(event);
               }
           },
 
           onDeleteItem: function tTO_onDeleteItem(aDeletedItem) {
-              if (cal.isToDo(aDeletedItem) && !this.mBatchCount) {
+              if (cal.isToDo(aDeletedItem)) {
 
                   // get occurrences of repeating items
                   let occs;
                   if (this.binding.mFilter.endDate) {
                       occs = aDeletedItem.getOccurrencesBetween(this.binding.mFilter.startDate,
                                                                 this.binding.mFilter.endDate,
                                                                 {});
                   } else {
--- a/calendar/base/content/calendar-unifinder.js
+++ b/calendar/base/content/calendar-unifinder.js
@@ -90,68 +90,61 @@ function getCurrentUnifinderFilter() {
 /**
  * Observer for the calendar event data source. This keeps the unifinder
  * display up to date when the calendar event data is changed
  *
  * @see calIObserver
  * @see calICompositeObserver
  */
 var unifinderObserver = {
-    mInBatch: false,
 
     QueryInterface: function uO_QueryInterface (aIID) {
         return cal.doQueryInterface(this,
                                     null, // this singleton has no prototype
                                     aIID,
                                     [Components.interfaces.calICompositeObserver,
                                      Components.interfaces.nsIObserver,
                                      Components.interfaces.calIObserver]);
     },
 
     // calIObserver:
     onStartBatch: function uO_onStartBatch() {
-        this.mInBatch = true;
     },
 
     onEndBatch: function uO_onEndBatch() {
-        this.mInBatch = false;
         refreshEventTree();
     },
 
     onLoad: function uO_onLoad() {
         if (isUnifinderHidden() && !gUnifinderNeedsRefresh) {
             // 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();
         }
-        if (!this.mInBatch) {
-            refreshEventTree();
-        }
     },
 
     onAddItem: function uO_onAddItem(aItem) {
         if (isEvent(aItem) &&
-            !this.mInBatch &&
             !gUnifinderNeedsRefresh &&
             unifinderTreeView.mFilter.isItemInFilters(aItem)
             ) {
             this.addItemToTree(aItem);
         }
     },
 
     onModifyItem: function uO_onModifyItem(aNewItem, aOldItem) {
         this.onDeleteItem(aOldItem);
         this.onAddItem(aNewItem);
     },
 
     onDeleteItem: function uO_onDeleteItem(aDeletedItem) {
-        if (isEvent(aDeletedItem) && !this.mInBatch && !gUnifinderNeedsRefresh) {
+        if (isEvent(aDeletedItem) && !gUnifinderNeedsRefresh) {
             this.removeItemFromTree(aDeletedItem);
         }
     },
 
     onError: function uO_onError(aCalendar, aErrNo, aMessage) {},
 
     onPropertyChanged: function uO_onPropertyChanged(aCalendar, aName, aValue, aOldValue) {
         switch (aName) {
@@ -162,24 +155,24 @@ var unifinderObserver = {
     },
 
     onPropertyDeleting: function uO_onPropertyDeleting(aCalendar, aName) {
       this.onPropertyChanged(aCalendar, aName, null, null);
     },
 
     // calICompositeObserver:
     onCalendarAdded: function uO_onCalendarAdded(aAddedCalendar) {
-        if (!this.mInBatch && !aAddedCalendar.getProperty("disabled")) {
+        if (!aAddedCalendar.getProperty("disabled")) {
             addItemsFromCalendar(aAddedCalendar,
                                  addItemsFromSingleCalendarInternal);
         }
     },
 
     onCalendarRemoved: function uO_onCalendarRemoved(aDeletedCalendar) {
-        if (!this.mInBatch && !aDeletedCalendar.getProperty("disabled")) {
+        if (!aDeletedCalendar.getProperty("disabled")) {
             deleteItemsFromCalendar(aDeletedCalendar);
         }
     },
 
     onDefaultCalendarChanged: function uO_onDefaultCalendarChanged(aNewDefaultCalendar) {},
 
     /**
      * Add an unifinder item to the tree. It is safe to call these for any
--- a/calendar/base/content/widgets/minimonth.xml
+++ b/calendar/base/content/widgets/minimonth.xml
@@ -625,27 +625,21 @@
         }
         ]]></body>
       </method>
 
        <!--calIObserver methods -->
       <method name="onStartBatch">
         <parameter name="aCalendar"/>
         <body><![CDATA[
-            this.mBatchCount++;
         ]]></body>
       </method>
 
       <method name="onEndBatch">
         <parameter name="aCalendar"/>
-          this.mBatchCount--;
-          if (this.mBatchCount == 0) {
-              this.resetAttributesForDate();
-              this.getItems();
-          }
         <body><![CDATA[
         ]]></body>
       </method>
 
       <method name="onLoad">
         <parameter name="aCalendar"/>
         <body><![CDATA[
         ]]></body>