forked from Qortal/qortal
Attempt to differentiate between resources that are downloading, and ones where downloading hasn't been attempted yet.
This commit is contained in:
parent
e481a5926a
commit
c7c88dec04
@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
public class ArbitraryResourceSummary {
|
||||
|
||||
public enum ArbitraryResourceStatus {
|
||||
NOT_STARTED,
|
||||
DOWNLOADING,
|
||||
DOWNLOADED,
|
||||
BUILDING,
|
||||
|
@ -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()) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user