Possibly optimise download speed by rate-limiting update messages?

master
Nekojimi 1 month ago
parent 268af0ff3f
commit c2c748470f
  1. 18
      src/main/java/moe/nekojimi/chords/Chords.java

@ -437,6 +437,9 @@ public final class Chords extends ListenerAdapter
private static final String PROGRESS_SYMBOLS = " ▏▎▍▌▋▊▉█";
private double lastProgressUpdate = 0.0;
private boolean initialUpdateSent = false;
/*
🌑🌘🌗🌖🌕
@ -455,6 +458,7 @@ public final class Chords extends ListenerAdapter
@Override
public void accept(TrackRequest request, Exception ex)
{
boolean shouldUpdate = false;
String response = "";
if (request.getTracks().size() > 1)
response += "Downloading " + request.getTracks().size() + " tracks:\n";
@ -467,6 +471,7 @@ public final class Chords extends ListenerAdapter
{
response += ("Finished downloading " + track + "!");
log("DOWN", "Downloaded " + track);
shouldUpdate = true;
} else
{
Format format = track.getBestFormat();
@ -482,7 +487,14 @@ public final class Chords extends ListenerAdapter
String progressDetails = "";
if (track.getProgress() >= 0)
{
if (track.getProgress() >= lastProgressUpdate + 10.0)
{
shouldUpdate = true;
lastProgressUpdate = track.getProgress();
}
progressDetails = " [" + String.format("%.1f", track.getProgress()) + "%]";
}
response += ("Now downloading " + track + formatDetails + progressDetails + " ...");
log("DOWN", "Downloading " + track + "...");
@ -491,11 +503,15 @@ public final class Chords extends ListenerAdapter
{
response += ("Failed to download " + track + "! Reason: " + ex.getMessage());
log("DOWN", "Failed to download " + track + "! Reason: " + ex.getMessage());
shouldUpdate = true;
}
response += "\n";
}
if (!response.isEmpty())
if (!response.isEmpty() && (shouldUpdate || initialUpdateSent))
{
request.getInvocation().respond(response);
initialUpdateSent = true;
}
}
}

Loading…
Cancel
Save