From d00c320c0041421e67d5d8ec6deb4427d0f8020c Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 24 Mar 2022 18:39:53 -0300 Subject: 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. --- launcher/ui/pages/modplatform/ModModel.cpp | 33 +++++++++++++++++++----------- launcher/ui/pages/modplatform/ModModel.h | 3 +++ 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'launcher/ui/pages') 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((dynamic_cast(parent()))->m_instance))->getPackProfile()->getComponentVersion("net.minecraft"); - bool hasFabric = !(dynamic_cast((dynamic_cast(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((dynamic_cast(parent()))->m_instance)) + ->getPackProfile() + ->getComponentVersion("net.fabricmc.fabric-loader") + .isEmpty(); +} + +auto ModPlatform::ListModel::getMineVersions() const -> QList +{ + return { (dynamic_cast((dynamic_cast(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; + protected: ModPage* m_parent; -- cgit