Skip to content

Commit

Permalink
Merge pull request ebkr#1487 from ebkr/memory-optimization-pt6-Thunde…
Browse files Browse the repository at this point in the history
…rstoreMod

Drop ThunderstoreVersion references from ThunderstoreMod
  • Loading branch information
anttimaki authored Oct 18, 2024
2 parents ea7643f + 4c2db6c commit 805d5bc
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 86 deletions.
4 changes: 2 additions & 2 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<ul class="list">
<li class="list-item" v-for='(mod, index) in $store.getters["profile/modsWithUpdates"]'
:key='`to-update-${index}-${mod.getFullName()}`'>
{{mod.getName()}} will be updated to: {{mod.getLatestVersion().getVersionNumber().toString()}}
{{mod.getName()}} will be updated to: {{mod.getLatestVersion()}}
</li>
</ul>
</template>
Expand Down Expand Up @@ -223,7 +223,7 @@ let assignId = 0;
async getModVersions() {
this.currentVersion = null;
if (this.thunderstoreMod !== null) {
this.selectedVersion = this.thunderstoreMod.getLatestVersion().getVersionNumber().toString();
this.selectedVersion = this.thunderstoreMod.getLatestVersion();
this.recommendedVersion = null;
this.versionNumbers = await PackageDb.getPackageVersionNumbers(
Expand Down
22 changes: 8 additions & 14 deletions src/components/views/OnlineModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v-for='(key, index) in pagedModList' :key="`online-${key.getFullName()}-${index}-${settings.getContext().global.expandedCards}`"
:image="getImageUrl(key)"
:id="index"
:description="key.getLatestVersion().getDescription()">
:description="key.getDescription()">
<template v-slot:title>
<span v-if="key.isPinned()">
<span class="tag is-info margin-right margin-right--half-width"
Expand Down Expand Up @@ -100,34 +100,28 @@ export default class OnlineModList extends Vue {
return this.$store.state.tsMods.deprecated;
}
isModDeprecated(key: any) {
const mod: ThunderstoreMod = new ThunderstoreMod().fromReactive(key);
isModDeprecated(mod: ThunderstoreMod) {
return this.deprecationMap.get(mod.getFullName()) || false;
}
isThunderstoreModInstalled(vueMod: any) {
const mod: ThunderstoreMod = new ThunderstoreMod().fromReactive(vueMod);
isThunderstoreModInstalled(mod: ThunderstoreMod) {
return this.localModList.find((local: ManifestV2) => local.getName() === mod.getFullName()) != undefined;
}
showDownloadModal(mod: any) {
const modToDownload = new ThunderstoreMod().fromReactive(mod);
this.$store.commit("openDownloadModModal", modToDownload);
showDownloadModal(mod: ThunderstoreMod) {
this.$store.commit("openDownloadModModal", mod);
}
getReadableDate(date: Date): string {
return valueToReadableDate(date);
}
getReadableCategories(tsMod: ThunderstoreMod) {
const mod = new ThunderstoreMod().fromReactive(tsMod);
getReadableCategories(mod: ThunderstoreMod) {
return mod.getCategories().join(", ");
}
getImageUrl(tsMod: ThunderstoreMod): string {
return CdnProvider.replaceCdnHost(
tsMod.getLatestVersion().getIcon()
);
getImageUrl(mod: ThunderstoreMod): string {
return CdnProvider.replaceCdnHost(mod.getIcon());
}
async created() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/OnlineModView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class OnlineModView extends Vue {
const searchKeys = SearchUtils.makeKeys(this.thunderstoreSearchFilter);
if (searchKeys.length > 0) {
searchableList = this.sortedThunderstoreModList.filter((x: ThunderstoreMod) => {
return SearchUtils.isSearched(searchKeys, x.getFullName(), x.getLatestVersion().getDescription())
return SearchUtils.isSearched(searchKeys, x.getFullName(), x.getDescription())
});
}
if (!allowNsfw) {
Expand Down
63 changes: 14 additions & 49 deletions src/model/ThunderstoreMod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import ThunderstoreVersion from './ThunderstoreVersion';
import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';

export default class ThunderstoreMod extends ThunderstoreVersion implements ReactiveObjectConverterInterface {
private versions: ThunderstoreVersion[] = [];
export default class ThunderstoreMod extends ThunderstoreVersion {
private rating: number = 0;
private owner: string = '';
private packageUrl: string = '';
Expand All @@ -15,6 +13,7 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
private categories: string[] = [];
private hasNsfwContent: boolean = false;
private donationLink: string | undefined;
private latestVersion: string = '';

public static parseFromThunderstoreData(data: any): ThunderstoreMod {
const mod = new ThunderstoreMod();
Expand All @@ -25,63 +24,33 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
mod.setDateUpdated(data.date_updated);
mod.setDeprecatedStatus(data.is_deprecated);
mod.setPinnedStatus(data.is_pinned);
const versions = [];
for (const version of data.versions) {
versions.push(new ThunderstoreVersion().make(version));
}
mod.setVersions(versions);
mod.setDownloadCount(
mod.versions
.map(version => version.getDownloadCount())
.reduce((x, y) => x + y)
);
mod.setRating(data.rating_score);
mod.setTotalDownloads(
mod.getVersions()
.map(x => x.getDownloadCount())
.reduce((x, y) => x + y)
data.versions.reduce(
(x: number, y: {downloads: number}) => x + y.downloads,
0
)
);
mod.setPackageUrl(data.package_url);
mod.setCategories(data.categories);
mod.setNsfwFlag(data.has_nsfw_content);
mod.setDonationLink(data.donation_link);
mod.setLatestVersion(data.versions[0].version_number);
mod.setDescription(data.versions[0].description);
mod.setIcon(data.versions[0].icon);
return mod;
}

public fromReactive(reactive: any): ThunderstoreMod {
this.setName(reactive.name);
this.setFullName(reactive.fullName);
this.setOwner(reactive.owner);
this.setPackageUrl(reactive.packageUrl);
this.setDateCreated(reactive.dateCreated);
this.setDateUpdated(reactive.dateUpdated);
this.setDeprecatedStatus(reactive.deprecated);
this.setPinnedStatus(reactive.pinned);
this.setVersions(reactive.versions.map((x: ThunderstoreVersion) => new ThunderstoreVersion().fromReactive(x)));
this.setDownloadCount(reactive.downloadCount);
this.setRating(reactive.rating);
this.setTotalDownloads(reactive.totalDownloads);
this.setUuid4(reactive.uuid4);
this.setCategories(reactive.categories);
this.setNsfwFlag(reactive.hasNsfwContent);
this.setDonationLink(reactive.donationUrl);
return this;
}

public getVersions(): ThunderstoreVersion[] {
return this.versions;
public getLatestVersion(): string {
return this.latestVersion;
}

public setVersions(versions: ThunderstoreVersion[]) {
this.versions = versions;
}

public getLatestVersion(): ThunderstoreVersion {
return this.getVersions().reduce(reduceToNewestVersion);
public setLatestVersion(versionNumber: string) {
this.latestVersion = versionNumber;
}

public getLatestDependencyString(): string {
return `${this.getFullName()}-${this.getLatestVersion().toString()}`;
return `${this.getFullName()}-${this.getLatestVersion()}`;
}

public getRating(): number {
Expand Down Expand Up @@ -180,7 +149,3 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
this.donationLink = url;
}
}

function reduceToNewestVersion(v1: ThunderstoreVersion, v2: ThunderstoreVersion) {
return v1.getVersionNumber().isNewerThan(v2.getVersionNumber()) ? v1 : v2;
};
16 changes: 1 addition & 15 deletions src/model/ThunderstoreVersion.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import VersionNumber from './VersionNumber';
import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
import CdnProvider from '../providers/generic/connection/CdnProvider';

export default class ThunderstoreVersion implements ReactiveObjectConverterInterface {
export default class ThunderstoreVersion {

private name: string = '';
private versionNumber: VersionNumber = new VersionNumber('0.0.0');
Expand Down Expand Up @@ -32,19 +31,6 @@ export default class ThunderstoreVersion implements ReactiveObjectConverterInter
return this;
}

public fromReactive(reactive: any): ThunderstoreVersion {
this.setName(reactive.name);
this.setVersionNumber(new VersionNumber('0.0.0').fromReactive(reactive.versionNumber));
this.setDependencies(reactive.dependencies);
this.setFullName(reactive.fullName);
this.setDescription(reactive.description);
this.setIcon(reactive.icon);
this.enabled = reactive.enabled;
this.setDownloadCount(reactive.downloadCount);
this.setDownloadUrl(reactive.downloadUrl);
return this;
}

public getName(): string {
return this.name;
}
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ActionTree, GetterTree, MutationTree } from 'vuex';
import { State as RootState } from '../index';
import ManifestV2 from '../../model/ManifestV2';
import ThunderstoreMod from '../../model/ThunderstoreMod';
import VersionNumber from '../../model/VersionNumber';
import CdnProvider from '../../providers/generic/connection/CdnProvider';
import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider';
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
Expand Down Expand Up @@ -80,7 +81,7 @@ export const TsModsModule = {
if (tsMod === undefined) {
state.cache.set(cacheKey, {tsMod: undefined, isLatest: true});
} else {
const latestVersionNumber = tsMod.getLatestVersion().getVersionNumber();
const latestVersionNumber = new VersionNumber(tsMod.getLatestVersion());
const isLatest = mod.getVersionNumber().isEqualOrNewerThan(latestVersionNumber);
state.cache.set(cacheKey, {tsMod, isLatest});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ const createStubMod = (
mod.setFullName(modName);
mod.setDeprecatedStatus(deprecated);

const version = new ThunderstoreVersion();
version.setFullName(`${mod}-1.0.0`);
version.setDependencies(dependencyNames.map((depName) => `${depName}-1.0.0`));
mod.setVersions([version]);
// const version = new ThunderstoreVersion();
// version.setFullName(`${mod}-1.0.0`);
// version.setDependencies(dependencyNames.map((depName) => `${depName}-1.0.0`));
// mod.setVersions([version]);

return mod;
}

0 comments on commit 805d5bc

Please sign in to comment.