Skip to content

Commit 3662fdf

Browse files
committed
Drop ThunderstoreVersion references from ThunderstoreMod
Commonly used version-specific data - latest version number, icon and description are now stored in the ThunderstoreMod object. Rest of the version info needs to be fetched separately where it's actually used. This change drastically reduces memory usage for larger communities like Lethal Company.
1 parent baa2140 commit 3662fdf

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
lines changed

src/components/views/DownloadModModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<ul class="list">
7878
<li class="list-item" v-for='(mod, index) in $store.getters["profile/modsWithUpdates"]'
7979
:key='`to-update-${index}-${mod.getFullName()}`'>
80-
{{mod.getName()}} will be updated to: {{mod.getLatestVersion().getVersionNumber().toString()}}
80+
{{mod.getName()}} will be updated to: {{mod.getLatestVersion()}}
8181
</li>
8282
</ul>
8383
</template>
@@ -223,7 +223,7 @@ let assignId = 0;
223223
async getModVersions() {
224224
this.currentVersion = null;
225225
if (this.thunderstoreMod !== null) {
226-
this.selectedVersion = this.thunderstoreMod.getLatestVersion().getVersionNumber().toString();
226+
this.selectedVersion = this.thunderstoreMod.getLatestVersion();
227227
this.recommendedVersion = null;
228228
229229
this.versionNumbers = await PackageDb.getPackageVersionNumbers(

src/components/views/OnlineModList.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v-for='(key, index) in pagedModList' :key="`online-${key.getFullName()}-${index}-${settings.getContext().global.expandedCards}`"
55
:image="getImageUrl(key)"
66
:id="index"
7-
:description="key.getLatestVersion().getDescription()">
7+
:description="key.getDescription()">
88
<template v-slot:title>
99
<span v-if="key.isPinned()">
1010
<span class="tag is-info margin-right margin-right--half-width"
@@ -121,9 +121,7 @@ export default class OnlineModList extends Vue {
121121
}
122122
123123
getImageUrl(mod: ThunderstoreMod): string {
124-
return CdnProvider.replaceCdnHost(
125-
mod.getLatestVersion().getIcon()
126-
);
124+
return CdnProvider.replaceCdnHost(mod.getIcon());
127125
}
128126
129127
async created() {

src/components/views/OnlineModView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default class OnlineModView extends Vue {
147147
const searchKeys = SearchUtils.makeKeys(this.thunderstoreSearchFilter);
148148
if (searchKeys.length > 0) {
149149
searchableList = this.sortedThunderstoreModList.filter((x: ThunderstoreMod) => {
150-
return SearchUtils.isSearched(searchKeys, x.getFullName(), x.getLatestVersion().getDescription())
150+
return SearchUtils.isSearched(searchKeys, x.getFullName(), x.getDescription())
151151
});
152152
}
153153
if (!allowNsfw) {

src/model/ThunderstoreMod.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ThunderstoreVersion from './ThunderstoreVersion';
2+
import VersionNumber from './VersionNumber';
23

34
export default class ThunderstoreMod extends ThunderstoreVersion {
4-
private versions: ThunderstoreVersion[] = [];
55
private rating: number = 0;
66
private owner: string = '';
77
private packageUrl: string = '';
@@ -14,6 +14,7 @@ export default class ThunderstoreMod extends ThunderstoreVersion {
1414
private categories: string[] = [];
1515
private hasNsfwContent: boolean = false;
1616
private donationLink: string | undefined;
17+
private latestVersion: string = '';
1718

1819
public static parseFromThunderstoreData(data: any): ThunderstoreMod {
1920
const mod = new ThunderstoreMod();
@@ -24,43 +25,37 @@ export default class ThunderstoreMod extends ThunderstoreVersion {
2425
mod.setDateUpdated(data.date_updated);
2526
mod.setDeprecatedStatus(data.is_deprecated);
2627
mod.setPinnedStatus(data.is_pinned);
27-
const versions = [];
28-
for (const version of data.versions) {
29-
versions.push(new ThunderstoreVersion().make(version));
30-
}
31-
mod.setVersions(versions);
32-
mod.setDownloadCount(
33-
mod.versions
34-
.map(version => version.getDownloadCount())
35-
.reduce((x, y) => x + y)
36-
);
3728
mod.setRating(data.rating_score);
3829
mod.setTotalDownloads(
39-
mod.getVersions()
40-
.map(x => x.getDownloadCount())
41-
.reduce((x, y) => x + y)
30+
data.versions.reduce(
31+
(x: number, y: {downloads: number}) => x + y.downloads,
32+
0
33+
)
4234
);
4335
mod.setPackageUrl(data.package_url);
4436
mod.setCategories(data.categories);
4537
mod.setNsfwFlag(data.has_nsfw_content);
4638
mod.setDonationLink(data.donation_link);
39+
mod.setLatestVersion(data.versions[0].version_number);
40+
mod.setDescription(data.versions[0].description);
41+
mod.setIcon(data.versions[0].icon);
4742
return mod;
4843
}
4944

50-
public getVersions(): ThunderstoreVersion[] {
51-
return this.versions;
45+
public getLatestVersion(): string {
46+
return this.latestVersion;
5247
}
5348

54-
public setVersions(versions: ThunderstoreVersion[]) {
55-
this.versions = versions;
49+
public setLatestVersion(versionNumber: string) {
50+
this.latestVersion = versionNumber;
5651
}
5752

58-
public getLatestVersion(): ThunderstoreVersion {
59-
return this.getVersions().reduce(reduceToNewestVersion);
53+
public getLatestVersionNumber(): VersionNumber {
54+
return new VersionNumber(this.latestVersion);
6055
}
6156

6257
public getLatestDependencyString(): string {
63-
return `${this.getFullName()}-${this.getLatestVersion().toString()}`;
58+
return `${this.getFullName()}-${this.getLatestVersion()}`;
6459
}
6560

6661
public getRating(): number {

src/store/modules/TsModsModule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ export const TsModsModule = {
8080
if (tsMod === undefined) {
8181
state.cache.set(cacheKey, {tsMod: undefined, isLatest: true});
8282
} else {
83-
const latestVersionNumber = tsMod.getLatestVersion().getVersionNumber();
84-
const isLatest = mod.getVersionNumber().isEqualOrNewerThan(latestVersionNumber);
83+
const isLatest = mod.getVersionNumber().isEqualOrNewerThan(tsMod.getLatestVersionNumber());
8584
state.cache.set(cacheKey, {tsMod, isLatest});
8685
}
8786
}

src/utils/Deprecations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class Deprecations {
5252
deprecationMap.set(mod.getFullName(), false);
5353
return false;
5454

55+
// TODO: version information was dropped from ThunderstoreMod to
56+
// save memory. Accessing dependencies weren't added to the class
57+
// since it's not currently used anywhere. Consider adding a
58+
// method for this purpose if this code is ever actually used.
5559
// for (const dependencyNameAndVersion of mod.getLatestVersion().getDependencies()) {
5660
// const dependencyName = dependencyNameAndVersion.substring(0, dependencyNameAndVersion.lastIndexOf('-'));
5761

test/jest/__tests__/utils/utils.getDeprecatedPackageMap.ts.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ const createStubMod = (
227227
mod.setFullName(modName);
228228
mod.setDeprecatedStatus(deprecated);
229229

230-
const version = new ThunderstoreVersion();
231-
version.setFullName(`${mod}-1.0.0`);
232-
version.setDependencies(dependencyNames.map((depName) => `${depName}-1.0.0`));
233-
mod.setVersions([version]);
230+
// TODO: ThunderstoreMod no longer carries information about versions.
231+
// const version = new ThunderstoreVersion();
232+
// version.setFullName(`${mod}-1.0.0`);
233+
// version.setDependencies(dependencyNames.map((depName) => `${depName}-1.0.0`));
234+
// mod.setVersions([version]);
234235

235236
return mod;
236237
}

0 commit comments

Comments
 (0)