Skip to content

Commit 7f8592f

Browse files
committed
update(main): Lowering requests for badge fetchers
1 parent 0c2f1a3 commit 7f8592f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Styles/NewGJCommentList.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <Geode/modify/CommentCell.hpp>
88
#include <Geode/utils/web.hpp>
99

10-
std::string result_global = "";
10+
std::string badgesDataComments = "";
1111

1212
int hexStringToInt(const std::string& hexStr) {
1313
int value;
@@ -196,11 +196,16 @@ class $modify(CommentCell) {
196196
badgeHandle(result, cell, cell->m_comment->m_commentID);
197197
};
198198

199+
if (!badgesDataComments.empty()) {
200+
then(badgesDataComments);
201+
return;
202+
}
203+
199204
m_fields->m_listener.bind([then = std::move(then)] (web::WebTask::Event* e) {
200205
if (web::WebResponse* res = e->getValue()) {
201206
if (res->ok()) {
202-
result_global = res->string().unwrapOrDefault();
203-
then(result_global);
207+
badgesDataComments = res->string().unwrapOrDefault();
208+
then(badgesDataComments);
204209
}
205210
}
206211
});

src/Styles/NewProfilePage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <Geode/modify/ProfilePage.hpp>
55
#include <Geode/utils/web.hpp>
66

7+
std::string badgesDataProfile = "";
8+
79
void NewProfilePage::onBadgePressed(CCObject* pSender) {
810
geode::log::info("Object: {}", static_cast<CCNode*>(pSender)->getUserObject());
911
CCInteger* score = static_cast<CCInteger*>(static_cast<CCNode*>(pSender)->getUserObject());
@@ -192,6 +194,8 @@ class $modify(ProfilePage) {
192194

193195
void requestGDUtilsBadges(int accountID, CCLayer* layer) {
194196
const std::function<void(std::string const&)> then = [this, accountID, layer](std::string const& result) {
197+
badgesDataProfile = result;
198+
195199
std::vector<std::string> data_user = MoreLeaderboards::getWords(result, "|");
196200

197201
while (data_user.size() > 0) {
@@ -269,6 +273,13 @@ class $modify(ProfilePage) {
269273
log::error("Failed to get GDUtils badges: {}", error);
270274
};
271275

276+
// If we already have the badges data, don't request it again
277+
if (badgesDataProfile != "") {
278+
then(badgesDataProfile);
279+
return;
280+
}
281+
282+
// Request the badges data
272283
m_fields->m_listener.bind([expect = std::move(expect), then = std::move(then)] (web::WebTask::Event* e) {
273284
if (web::WebResponse* res = e->getValue()) {
274285
if (res->ok()) {

0 commit comments

Comments
 (0)