Skip to content

Commit

Permalink
Optimize ProfileModule.visibleModList getter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anttimaki committed Feb 15, 2024
1 parent c0cae0e commit 21bce97
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,30 @@ export default {
}),

getters: <GetterTree<State, RootState>>{
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
Expand Down

0 comments on commit 21bce97

Please # to comment.