Debugging guild get endpoint taking too long to execute

We have narrowed down where the slowdown starts and ends, however there
is still a lot of things happening between there, so therefore we are
checking what parts of those sections of the code are causing issues.
This commit is contained in:
NovaFox161
2020-03-31 22:55:35 -05:00
parent 1f5668a128
commit 036596f552
2 changed files with 15 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package org.dreamexposure.discal.core.object.web;
import org.dreamexposure.discal.core.database.DatabaseManager;
import org.dreamexposure.discal.core.logger.Logger;
import org.dreamexposure.discal.core.object.GuildSettings;
import org.dreamexposure.discal.core.object.announcement.Announcement;
import org.dreamexposure.discal.core.utils.GuildUtils;
@@ -147,31 +148,41 @@ public class WebGuild {
//Functions
public WebGuild fromGuild(Guild g) {
Logger.getLogger().debug("web guild conversion p1", true);
id = g.getId().asLong();
name = g.getName();
Logger.getLogger().debug("web guild conversion p2", true);
if (g.getIconUrl(Image.Format.PNG).isPresent())
iconUrl = g.getIconUrl(Image.Format.PNG).get();
Logger.getLogger().debug("web guild conversion p3", true);
botNick = g.getClient().getSelf().flatMap(user -> user.asMember(g.getId())).map(Member::getNickname).block().orElse("DisCal");
Logger.getLogger().debug("web guild conversion p4", true);
settings = DatabaseManager.getManager().getSettings(g.getId());
Logger.getLogger().debug("web guild conversion p5", true);
//Handle lists and stuffs
for (Role r : g.getRoles().toIterable()) {
roles.add(new WebRole().fromRole(r, settings));
}
Logger.getLogger().debug("web guild conversion p6", true);
WebChannel all = new WebChannel();
all.setId(0);
all.setName("All Channels");
all.setDiscalChannel(settings.getDiscalChannel().equalsIgnoreCase("all"));
channels.add(all);
Logger.getLogger().debug("web guild conversion p7", true);
for (GuildChannel c : g.getChannels().toIterable()) {
if (c instanceof TextChannel)
channels.add(new WebChannel().fromChannel((TextChannel) c, settings));
}
Logger.getLogger().debug("web guild conversion p8", true);
announcements.addAll(DatabaseManager.getManager().getAnnouncements(g.getId()));
Logger.getLogger().debug("web guild conversion p9", true);
calendar = new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Snowflake.of(id)), settings);
Logger.getLogger().debug("web guild conversion p10", true);
return this;
}

View File

@@ -37,9 +37,6 @@ public class GetWebGuildEndpoint {
response.setContentType("application/json");
return authState.toJson();
}
Logger.getLogger().debug("Handling guild get request 1p", true);
//Okay, now handle actual request.
try {
JSONObject jsonMain = new JSONObject(requestBody);
@@ -49,27 +46,25 @@ public class GetWebGuildEndpoint {
Guild g = DisCalServer.getClient()
.getGuildById(guildId).onErrorResume(e -> Mono.empty()).block();
Logger.getLogger().debug("Handling guild get request 2p", true);
if (g != null) {
//Start slowdown
Logger.getLogger().debug("Guild get endpoint slowdown starts here", true);
WebGuild wg = new WebGuild().fromGuild(g);
Logger.getLogger().debug("Handling guild get request 3.1p", true);
Member m = g.getMemberById(userId).onErrorResume(e -> Mono.empty()).block();
Logger.getLogger().debug("Handling guild get request 3.2p", true);
if (m != null) { //Assume false if we can't get the user...
wg.setManageServer(PermissionChecker.hasManageServerRole(m));
wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, m));
}
Logger.getLogger().debug("Handling guild get request 3.3p", true);
//End slowdown
Logger.getLogger().debug("Guild get endpoint slowdown ends here", true);
//Add available langs so that editing of langs can be done on the website
//noinspection unchecked
for (String l : new ArrayList<String>(ReadFile.readAllLangFiles().keySet())) {
wg.getAvailableLangs().add(l);
}
Logger.getLogger().debug("Handling guild get request 3.4p", true);
response.setContentType("application/json");
response.setStatus(200);