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

Update all - query performance #1203

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 14 additions & 2 deletions src/model/VersionNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export default class VersionNumber implements ReactiveObjectConverterInterface {
} else {
throw Error(`VersionNumber: Number found was NaN. Received: ${splitNumbers}`);
}
})
});
// If successful, assign values.
this.major = numberArray[0];
this.minor = numberArray[1];
this.patch = numberArray[2];
} catch(e) {
} catch (e) {
// If an error was thrown, log reason.
return new VersionNumber('0.0.0');
}
Expand Down Expand Up @@ -68,4 +68,16 @@ export default class VersionNumber implements ReactiveObjectConverterInterface {
public isEqualOrNewerThan(version: VersionNumber): boolean {
return this.isEqualTo(version) || this.isNewerThan(version);
}

public compareToDescending(version: VersionNumber): number {
var majorCompare = version.major - this.major;
var minorCompare = version.minor - this.minor;
var patchCompare = version.patch - this.patch;

return majorCompare == 0
? minorCompare == 0
? patchCompare
: minorCompare
: majorCompare;
}
}
10 changes: 10 additions & 0 deletions src/r2mm/data/ThunderstorePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import Game from '../../model/game/Game';
import ApiResponse from '../../model/api/ApiResponse';
import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider';
import ModBridge from '../mods/ModBridge';
import ThunderstoreVersion from 'src/model/ThunderstoreVersion';

export default class ThunderstorePackages {

public static PACKAGES: ThunderstoreMod[] = [];
public static PACKAGES_MAP: Map<String, ThunderstoreMod> = new Map();
public static EXCLUSIONS: string[] = [];
public static LATEST_VERSIONS: Map<String, ThunderstoreVersion> = new Map();

/**
* Fetch latest V1 API data and apply to {PACKAGES}
Expand Down Expand Up @@ -36,6 +38,14 @@ export default class ThunderstorePackages {
map.set(pkg.getFullName(), pkg);
return map;
}, new Map<String, ThunderstoreMod>());

ThunderstorePackages.LATEST_VERSIONS = ThunderstorePackages.PACKAGES.reduce((map, pkg) => {
ebkr marked this conversation as resolved.
Show resolved Hide resolved
var latestVersion = pkg.getVersions().sort((a, b) => a.getVersionNumber().compareToDescending(b.getVersionNumber()))[0];
if (latestVersion != undefined) {
map.set(pkg.getFullName(), latestVersion);
}
return map;
}, new Map<String, ThunderstoreVersion>());
}

public static getDeprecatedPackageMap(): Map<string, boolean> {
Expand Down
37 changes: 9 additions & 28 deletions src/r2mm/downloading/BetterThunderstoreDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,16 @@ export default class BetterThunderstoreDownloader extends ThunderstoreDownloader
}

public getLatestOfAllToUpdate(mods: ManifestV2[], allMods: ThunderstoreMod[]): ThunderstoreCombo[] {
var depMap: Map<string, ThunderstoreCombo> = new Map();
const dependencies: ThunderstoreCombo[] = [];
mods.forEach(value => {
const tsMod = ModBridge.getThunderstoreModFromMod(value, allMods);
if (tsMod !== undefined) {
this.buildDependencySetUsingLatest(tsMod.getVersions()![0], allMods, dependencies);
return mods.filter(mod => !ModBridge.isCachedLatestVersion(mod))
.map(mod => ModBridge.getCachedThunderstoreModFromMod(mod))
.filter(value => value != undefined)
.map(mod => {
const latestVersion = mod!.getVersions().sort((a, b) => a.getVersionNumber().compareToDescending(b.getVersionNumber()))[0];
const combo = new ThunderstoreCombo();
combo.setMod(tsMod);
combo.setVersion(tsMod.getVersions()![0])
dependencies.push(combo);
}
});

// Keep array unique in case scenario happens where dependency X is picked up before X install listing.
dependencies.forEach(value => depMap.set(value.getMod().getFullName(), value));

dependencies.forEach(value => {
depMap.set(value.getMod().getFullName(), value);
});

return Array.from(depMap.values()).filter(value => {
const result = mods.find(value1 => {
return value1.getName() === value.getMod().getFullName();
});
if (result !== undefined) {
return !result.getVersionNumber().isEqualTo(value.getVersion().getVersionNumber());
}
return false;
});
combo.setMod(mod!);
combo.setVersion(latestVersion);
return combo;
})
}

public async downloadLatestOfAll(game: Game, mods: ManifestV2[], allMods: ThunderstoreMod[],
Expand Down
Loading