Fix initialisation performance

The initialisation was setting the virtual list elements twice, causing
visible UI lag, partially due to a broken check for active filters,
which was also causing unnecessary calculations during other operations.
This commit is contained in:
Oliver Hamlet
2016-06-22 05:59:19 +01:00
parent 5fff69504b
commit f1655d4755
4 changed files with 90 additions and 10 deletions
+10 -2
View File
@@ -63,7 +63,11 @@ function onChangeGame(evt) {
loot.Filters.fillConflictsFilterList(loot.game.plugins);
/* Now update virtual lists. */
loot.filters.apply(loot.game.plugins);
if (loot.filters.areAnyFiltersActive()) {
loot.filters.apply(loot.game.plugins);
} else {
loot.DOM.initialiseVirtualLists(loot.game.plugins);
}
loot.Dialog.closeProgress();
}).catch(loot.handlePromiseError);
@@ -237,7 +241,11 @@ function onContentRefresh() {
loot.Filters.fillConflictsFilterList(loot.game.plugins);
/* Reapply filters. */
loot.filters.apply(loot.game.plugins);
if (loot.filters.areAnyFiltersActive()) {
loot.filters.apply(loot.game.plugins);
} else {
loot.DOM.initialiseVirtualLists(loot.game.plugins);
}
loot.Dialog.closeProgress();
}).catch(loot.handlePromiseError);
+2 -6
View File
@@ -100,8 +100,8 @@
areAnyFiltersActive() {
return this.hideMessagelessPlugins
|| this.hideInactivePlugins
|| this.conflictingPluginNames
|| this.contentSearchString
|| this.conflictingPluginNames.length !== 0
|| this.contentSearchString.length !== 0
|| this.hideVersionNumbers
|| this.hideCRCs
|| this.hideBashTags
@@ -120,10 +120,6 @@
}
apply(plugins) {
if (!this.areAnyFiltersActive()) {
return;
}
const filteredPlugins = plugins.filter(this.pluginFilter, this);
document.getElementById('cardsNav').items = filteredPlugins;
+6 -2
View File
@@ -176,10 +176,14 @@
const game = JSON.parse(result, Plugin.fromJson);
appData.game = new Game(game, appData.l10n);
dom.initialiseVirtualLists(appData.game.plugins);
appData.Filters.fillConflictsFilterList(appData.game.plugins);
appData.filters.load(appData.settings.filters);
appData.filters.apply(appData.game.plugins);
if (appData.filters.areAnyFiltersActive()) {
appData.filters.apply(appData.game.plugins);
} else {
dom.initialiseVirtualLists(appData.game.plugins);
}
Dialog.closeProgress();
});
+72
View File
@@ -255,4 +255,76 @@ describe('Filters', () => {
filters.activateConflictsFilter().should.finally.deepEqual([]);
});
});
describe('#areAnyFiltersActive', () => {
let filters;
beforeEach(() => {
filters = new loot.Filters(l10n);
});
it('should return false if all the boolean filters are false, and the content and conflict filter lengths are zero', () => {
filters.areAnyFiltersActive().should.be.false();
});
it('should return true if hideMessagelessPlugins is true', () => {
filters.hideMessagelessPlugins = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideInactivePlugins is true', () => {
filters.hideInactivePlugins = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideVersionNumbers is true', () => {
filters.hideVersionNumbers = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideCRCs is true', () => {
filters.hideCRCs = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideBashTags is true', () => {
filters.hideBashTags = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideAllPluginMessages is true', () => {
filters.hideAllPluginMessages = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideNotes is true', () => {
filters.hideNotes = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if hideDoNotCleanMessages is true', () => {
filters.hideDoNotCleanMessages = true;
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if conflictingPluginNames is a non-empty array', () => {
filters.conflictingPluginNames = ['foo'];
filters.areAnyFiltersActive().should.be.true();
});
it('should return true if contentSearchString is a non-empty string', () => {
filters.contentSearchString = 'foo';
filters.areAnyFiltersActive().should.be.true();
});
});
});