From 21bce979591a1af39ce2bd3a81f55455c1240559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 5 Feb 2024 12:09:16 +0200 Subject: [PATCH] Optimize ProfileModule.visibleModList getter Now that a separate orderedModList is no longer needed, we might as well combine the ordering and filtering into the same method, and do the fiiltering first to speed up ordering when searchQuery is used. --- src/store/modules/ProfileModule.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/store/modules/ProfileModule.ts b/src/store/modules/ProfileModule.ts index 768570ee8..0685d453b 100644 --- a/src/store/modules/ProfileModule.ts +++ b/src/store/modules/ProfileModule.ts @@ -29,34 +29,30 @@ export default { }), getters: >{ - orderedModList(state, _getters, rootState): ManifestV2[] { + visibleModList(state, _getters, rootState): ManifestV2[] { + let mods = [...rootState.localModList]; + + if (state.searchQuery) { + const searchKeys = SearchUtils.makeKeys(state.searchQuery); + mods = mods.filter( + (mod) => SearchUtils.isSearched(searchKeys, mod.getName(), mod.getDescription()) + ); + } + // Theoretically sorters can be undefined to avoid having to // mix ManagerSettings singleton to VueX store. if (!state.order || !state.direction || !state.disabledPosition) { - return [...rootState.localModList]; + return mods; } return ModListSort.sortLocalModList( - rootState.localModList, + mods, state.direction, state.disabledPosition, state.order ); }, - visibleModList(state, getters, rootState): ManifestV2[] { - const mods: ManifestV2[] = getters.orderedModList; - - if (!state.searchQuery) { - return mods; - } - - const searchKeys = SearchUtils.makeKeys(state.searchQuery); - return mods.filter( - (mod) => SearchUtils.isSearched(searchKeys, mod.getName(), mod.getDescription()) - ); - }, - canSortMods(state): boolean { return state.order === SortNaming.CUSTOM && state.direction === SortDirection.STANDARD