RCFilters: Don't reload results for redundant requests
authorMoriel Schottlender <moriel@gmail.com>
Tue, 1 Aug 2017 23:02:44 +0000 (16:02 -0700)
committerCatrope <roan@wikimedia.org>
Wed, 2 Aug 2017 00:30:59 +0000 (00:30 +0000)
Ignore reloading if the requests are:
- Change of inverted namespaces if there are no namespace items
  selected.
- Reloading of new saved query if that same query is already loaded

Bug: T172138
Change-Id: Id43bef8a08aab3412a6c5cb538d048935a178114

resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js

index 9d2c331..fbd44fd 100644 (file)
         */
        mw.rcfilters.Controller.prototype.toggleInvertedNamespaces = function () {
                this.filtersModel.toggleInvertedNamespaces();
-               this.updateChangesList();
+
+               if (
+                       this.filtersModel.getFiltersByView( 'namespaces' )
+                               .filter( function ( filterItem ) {
+                                       return filterItem.isSelected();
+                               } )
+                               .length
+               ) {
+                       // Only re-fetch results if there are namespace items that are actually selected
+                       this.updateChangesList();
+               }
        };
 
        /**
         */
        mw.rcfilters.Controller.prototype.applySavedQuery = function ( queryID ) {
                var data, highlights,
-                       queryItem = this.savedQueriesModel.getItemByID( queryID );
+                       queryItem = this.savedQueriesModel.getItemByID( queryID ),
+                       currentMatchingQuery = this.findQueryMatchingCurrentState();
 
-               if ( queryItem ) {
+               if (
+                       queryItem &&
+                       (
+                               // If there's already a query, don't reload it
+                               // if it's the same as the one that already exists
+                               !currentMatchingQuery ||
+                               currentMatchingQuery.getID() !== queryItem.getID()
+                       )
+               ) {
                        data = queryItem.getData();
                        highlights = data.highlights;