mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user