Attempt to differentiate between resources that are downloading, and ones where downloading hasn't been attempted yet.

This commit is contained in:
CalDescent 2021-12-10 12:22:26 +00:00
parent e481a5926a
commit c7c88dec04
3 changed files with 43 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
public class ArbitraryResourceSummary {
public enum ArbitraryResourceStatus {
NOT_STARTED,
DOWNLOADING,
DOWNLOADED,
BUILDING,

View File

@ -68,9 +68,12 @@ public class ArbitraryDataResource {
// Check if we have all data locally for this resource
if (!this.allFilesDownloaded()) {
if (this.isDataPotentiallyAvailable()) {
if (this.isDownloading()) {
return new ArbitraryResourceSummary(ArbitraryResourceStatus.DOWNLOADING);
}
else if (this.isDataPotentiallyAvailable()) {
return new ArbitraryResourceSummary(ArbitraryResourceStatus.NOT_STARTED);
}
return new ArbitraryResourceSummary(ArbitraryResourceStatus.MISSING_DATA);
}
@ -146,6 +149,40 @@ public class ArbitraryDataResource {
}
/**
* Best guess as to whether we are currently downloading a resource
* This is only used to give an indication to the user of progress
* @return - whether we are trying to download the resource
*/
private boolean isDownloading() {
try {
this.fetchTransactions();
Long now = NTP.getTime();
if (now == null) {
return false;
}
List<ArbitraryTransactionData> transactionDataList = new ArrayList<>(this.transactions);
for (ArbitraryTransactionData transactionData : transactionDataList) {
long lastRequestTime = ArbitraryDataManager.getInstance().lastRequestForSignature(transactionData.getSignature());
// If were have requested data in the last 30 seconds, treat it as "downloading"
if (lastRequestTime > 0 && now - lastRequestTime < 30 * 1000L) {
return true;
}
}
// FUTURE: we may want to check for file hashes (including the metadata file hash) in
// ArbitraryDataManager.arbitraryDataFileRequests and return true if one is found.
return false;
} catch (DataException e) {
return false;
}
}
private void fetchTransactions() throws DataException {
if (this.transactions != null && !this.transactions.isEmpty()) {

View File

@ -78,6 +78,10 @@
else if (json.status == "BUILD_FAILED") {
textStatus = "Build failed. Please try again later.";
}
else if (json.status == "NOT_STARTED") {
textStatus = "Waiting...";
retryInterval = 1000;
}
else if (json.status == "DOWNLOADING") {
textStatus = "Locating and downloading files...";
retryInterval = 1000;