Skip to content

Commit

Permalink
fix #152
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed Sep 19, 2022
1 parent 0bdb5a7 commit 50d8bf1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
}

group = "dev.isxander"
version = "2.6.1"
version = "2.6.2"

loom {
splitEnvironmentSourceSets()
Expand Down
1 change: 1 addition & 0 deletions changelogs/2.6.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix description loading causing long load times
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ public class BugFixDescriptionCache {
private final String url = "https://bugs.mojang.com/rest/api/2/issue/%s";

public void cacheDescriptions() {
Debugify.logger.info("Caching bug descriptions");
Debugify.logger.info("Connecting to 'bugs.mojang.com' to cache bug descriptions!");

HttpClient client = HttpClient.newHttpClient();
CompletableFuture.runAsync(() -> {
HttpClient client = HttpClient.newHttpClient();

for (BugFixData bugData : Debugify.config.getBugFixes().keySet()) {
String id = bugData.bugId();
try {
HttpRequest request = HttpRequest.newBuilder(new URI(String.format(url, id)))
.build();
for (BugFixData bugData : Debugify.config.getBugFixes().keySet()) {
String id = bugData.bugId();
try {
HttpRequest request = HttpRequest.newBuilder(new URI(String.format(url, id)))
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

if (response.statusCode() != 200) {
Debugify.logger.error("Description Cache: {} - {}", response.statusCode(), response.body());
continue;
}
if (response.statusCode() != 200) {
Debugify.logger.error("Description Cache: {} - {}", response.statusCode(), response.body());
continue;
}

JsonObject json = gson.fromJson(response.body(), JsonObject.class);
JsonObject fields = json.getAsJsonObject("fields");
String summary = fields.get("summary").getAsString();
JsonObject json = gson.fromJson(response.body(), JsonObject.class);
JsonObject fields = json.getAsJsonObject("fields");
String summary = fields.get("summary").getAsString();

descriptionHolder.put(id, summary);
} catch (Exception e) {
e.printStackTrace();
descriptionHolder.put(id, summary);
} catch (Exception e) {
e.printStackTrace();
}
}
}

save();
}).thenAccept((returnVal) -> save());
}

public void save() {
Expand Down

0 comments on commit 50d8bf1

Please sign in to comment.