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

Use cached mod methods in remaining files #1217

Merged
merged 1 commit 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
2 changes: 1 addition & 1 deletion src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ let assignId = 0;
this.$emit('error', localMods);
return;
}
const outdatedMods = localMods.filter(mod => !ModBridge.isLatestVersion(mod));
const outdatedMods = localMods.filter(mod => !ModBridge.isCachedLatestVersion(mod));
const currentAssignId = assignId++;
const progressObject = {
progress: 0,
Expand Down
5 changes: 2 additions & 3 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,8 @@ import { DeferredInput } from '../all';

updateMod(vueMod: any) {
this.selectedManifestMod = new ManifestV2().fromReactive(vueMod);
const mod = ModBridge.getThunderstoreModFromMod(
this.selectedManifestMod,
this.thunderstorePackages
const mod = ModBridge.getCachedThunderstoreModFromMod(
this.selectedManifestMod
);
if (mod instanceof ThunderstoreMod) {
this.$store.commit("openDownloadModModal", mod);
Expand Down
2 changes: 1 addition & 1 deletion src/model/ManifestV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export default class ManifestV2 implements ReactiveObjectConverterInterface {
}

public isDeprecated(): boolean {
const tsMod = ModBridge.getThunderstoreModFromMod(this, ThunderstorePackages.PACKAGES);
const tsMod = ModBridge.getCachedThunderstoreModFromMod(this);
return tsMod !== undefined ? tsMod.isDeprecated() : false;
}

Expand Down
8 changes: 7 additions & 1 deletion src/r2mm/mods/ModBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ export default class ModBridge {
return matchingMod.getVersions().reduce(reduceToNewestVersion);
}

/**
* @deprecated Please use {@link ModBridge.getCachedThunderstoreModFromMod} instead.
*/
public static getThunderstoreModFromMod(mod: ManifestV2, modList: ThunderstoreMod[]): ThunderstoreMod | undefined {
return modList.find((tsMod: ThunderstoreMod) => tsMod.getFullName() === mod.getName());
}

/**
* @deprecated Please use {@link ModBridge.isCachedLatestVersion} instead.
*/
public static isLatestVersion(vueMod: any): boolean {
const mod: ManifestV2 = new ManifestV2().fromReactive(vueMod);
const latestVersion: ThunderstoreVersion | void = ModBridge.getLatestVersion(mod, ThunderstorePackages.PACKAGES);
Expand All @@ -41,7 +47,7 @@ export default class ModBridge {
const cacheKey = `${mod.getName()}-${mod.getVersionNumber()}`;

if (ModBridge.CACHE[cacheKey] === undefined) {
const tsMod = ThunderstorePackages.PACKAGES.find((tsMod) => tsMod.getFullName() === mod.getName());
const tsMod = ThunderstorePackages.PACKAGES_MAP.get(mod.getName());

if (tsMod === undefined) {
ModBridge.CACHE[cacheKey] = { tsMod: undefined, isLatest: true };
Expand Down