Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LocalModCard performance #1206

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
@updateMod="updateMod"
@viewDependencyList="viewDependencyList"
@downloadDependency="downloadDependency"
:disabledDependencies="getDisabledDependencies(mod)"
:missingDependencies="getMissingDependencies(mod)"
:expandedByDefault="cardExpanded"
:showSort="$store.getters['profile/canSortMods']"
:funkyMode="funkyMode" />
Expand Down Expand Up @@ -141,25 +139,6 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
}
}

getMissingDependencies(mod: ManifestV2): string[] {
return mod.getDependencies().filter((dependency: string) => {
// Include in filter if mod isn't found.
return this.$store.state.localModList.find(
(localMod: ManifestV2) => dependency.toLowerCase().startsWith(localMod.getName().toLowerCase() + "-")
) === undefined;
});
}

getDisabledDependencies(mod: ManifestV2): ManifestV2[] {
const dependencies = mod
.getDependencies()
.map((x) => x.toLowerCase().substring(0, x.lastIndexOf('-') + 1));

return this.$store.state.localModList.filter(
(mod: ManifestV2) => !mod.isEnabled() && dependencies.includes(mod.getName().toLowerCase() + '-')
);
}

getDependantList(mod: ManifestV2): Set<ManifestV2> {
return Dependants.getDependantList(mod, this.$store.state.localModList);
}
Expand Down
51 changes: 44 additions & 7 deletions src/components/views/LocalModList/LocalModCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
import { ExpandableCard, Link } from '../../all';
import DonateButton from '../../buttons/DonateButton.vue';
import ManifestV2 from '../../../model/ManifestV2';
Expand All @@ -17,12 +17,6 @@ export default class LocalModCard extends Vue {
@Prop({required: true})
readonly mod!: ManifestV2;

@Prop({required: true})
readonly disabledDependencies!: ManifestV2[];

@Prop({required: true})
readonly missingDependencies!: string[];

@Prop({required: true})
readonly expandedByDefault!: boolean;

Expand All @@ -32,6 +26,9 @@ export default class LocalModCard extends Vue {
@Prop({required: true})
readonly funkyMode!: boolean;

disabledDependencies: ManifestV2[] = [];
missingDependencies: string[] = [];

get donationLink() {
return this.tsMod ? this.tsMod.getDonationLink() : undefined;
}
Expand All @@ -40,10 +37,42 @@ export default class LocalModCard extends Vue {
return ModBridge.isCachedLatestVersion(this.mod);
}

get localModList(): ManifestV2[] {
return this.$store.state.localModList;
}

get tsMod() {
return ModBridge.getCachedThunderstoreModFromMod(this.mod);
}

@Watch("localModList")
updateDependencies() {
if (this.mod.getDependencies().length === 0) {
return;
}

const dependencies = this.mod.getDependencies();
const dependencyNames = dependencies.map(dependencyStringToModName);
const foundDependencies: ManifestV2[] = [];

for (const mod of this.localModList) {
if (foundDependencies.length === dependencyNames.length) {
break;
}

if (dependencyNames.includes(mod.getName())) {
foundDependencies.push(mod);
}
}

const foundNames = foundDependencies.map((mod) => mod.getName());

this.disabledDependencies = foundDependencies.filter((d) => !d.isEnabled());
this.missingDependencies = dependencies.filter(
(d) => !foundNames.includes(dependencyStringToModName(d))
);
}

disableMod() {
this.$emit('disableMod', this.mod);
}
Expand All @@ -67,6 +96,14 @@ export default class LocalModCard extends Vue {
viewDependencyList() {
this.$emit('viewDependencyList', this.mod);
}

created() {
this.updateDependencies();
}
}

function dependencyStringToModName(x: string) {
return x.substring(0, x.lastIndexOf('-'));
}
</script>

Expand Down
Loading