diff options
author | flow <thiagodonato300@gmail.com> | 2022-03-24 18:39:53 -0300 |
---|---|---|
committer | flow <thiagodonato300@gmail.com> | 2022-03-24 19:31:11 -0300 |
commit | d00c320c0041421e67d5d8ec6deb4427d0f8020c (patch) | |
tree | 00f8bcdb15f5f98e969617b369cf15eb5847ef9f /launcher/ui | |
parent | e13ca94061c7fdfec9bd18b982b56a8d5a1f80b0 (diff) | |
download | PrismLauncher-d00c320c0041421e67d5d8ec6deb4427d0f8020c.tar.gz PrismLauncher-d00c320c0041421e67d5d8ec6deb4427d0f8020c.tar.bz2 PrismLauncher-d00c320c0041421e67d5d8ec6deb4427d0f8020c.zip |
optimize: Improve mod versions request to Modrinth
This uses more arguments in the GET request for mod versions on the
Modrinth API, filtering what versions can be returned, decreasing load
on Modrinth servers and improving a little the time it takes for the versions to be
available to the user.
This also removes the now unneeded check on correct modloaders in
ModrinthPackIndex, since it is now filtered by the Modrinth server.
Lastly, this adds a couple of helper functions in ModModel.
Diffstat (limited to 'launcher/ui')
-rw-r--r-- | launcher/ui/pages/modplatform/ModModel.cpp | 33 | ||||
-rw-r--r-- | launcher/ui/pages/modplatform/ModModel.h | 3 |
2 files changed, 24 insertions, 12 deletions
diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index cc3c5326..0a147584 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -16,7 +16,6 @@ auto ListModel::debugName() const -> QString return m_parent->debugName(); } - /******** Make data requests ********/ void ListModel::fetchMore(const QModelIndex& parent) @@ -61,19 +60,14 @@ auto ListModel::data(const QModelIndex& index, int role) const -> QVariant void ListModel::requestModVersions(ModPlatform::IndexedPack const& current) { - m_parent->apiProvider()->getVersions(this, current.addonId.toString()); + m_parent->apiProvider()->getVersions(this, + { current.addonId.toString(), getMineVersions(), hasFabric() ? ModAPI::ModLoaderType::Fabric : ModAPI::ModLoaderType::Forge }); } void ListModel::performPaginatedSearch() { - QString mcVersion = (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))->getPackProfile()->getComponentVersion("net.minecraft"); - bool hasFabric = !(dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance)) - ->getPackProfile() - ->getComponentVersion("net.fabricmc.fabric-loader") - .isEmpty(); - - m_parent->apiProvider()->searchMods( - this, { nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric ? ModAPI::Fabric : ModAPI::Forge, mcVersion }); + m_parent->apiProvider()->searchMods(this, + { nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric() ? ModAPI::Fabric : ModAPI::Forge, getMineVersions().at(0) }); } void ListModel::searchWithTerm(const QString& term, const int sort) @@ -131,7 +125,6 @@ void ListModel::requestLogo(QString logo, QString url) m_loadingLogos.append(logo); } - /******** Request callbacks ********/ void ListModel::logoLoaded(QString logo, QIcon out) @@ -208,7 +201,7 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId) { auto& current = m_parent->getCurrent(); if (addonId != current.addonId) { return; } - + QJsonArray arr = doc.array(); try { loadIndexedPackVersions(current, arr); @@ -221,3 +214,19 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId) } } // namespace ModPlatform + +/******** Helpers ********/ +auto ModPlatform::ListModel::hasFabric() const -> bool +{ + return !(dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance)) + ->getPackProfile() + ->getComponentVersion("net.fabricmc.fabric-loader") + .isEmpty(); +} + +auto ModPlatform::ListModel::getMineVersions() const -> QList<QString> +{ + return { (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance)) + ->getPackProfile() + ->getComponentVersion("net.minecraft") }; +} diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index 02be6049..64cfa71e 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -62,6 +62,9 @@ class ListModel : public QAbstractListModel { void requestLogo(QString file, QString url); + inline auto hasFabric() const -> bool; + inline auto getMineVersions() const -> QList<QString>; + protected: ModPage* m_parent; |