forked from Qortal/qortal
Added "priority" property to build queue items.
/render APIs use priority 10, whereas /arbitrary use priority 0, to prevent thumbnail downloads from holding up website loading. The priorities can be adjusted later, with maybe some service types being given higher priority than others.
This commit is contained in:
parent
2343e739d1
commit
6932fb9935
@ -1044,7 +1044,7 @@ public class ArbitraryResource {
|
||||
// Loop until we have data
|
||||
if (async) {
|
||||
// Asynchronous
|
||||
arbitraryDataReader.loadAsynchronously(false);
|
||||
arbitraryDataReader.loadAsynchronously(false, 0);
|
||||
}
|
||||
else {
|
||||
// Synchronous
|
||||
|
@ -13,6 +13,7 @@ public class ArbitraryDataBuildQueueItem extends ArbitraryDataResource {
|
||||
private final Long creationTimestamp;
|
||||
private Long buildStartTimestamp = null;
|
||||
private Long buildEndTimestamp = null;
|
||||
private Integer priority = 0;
|
||||
private boolean failed = false;
|
||||
|
||||
/* The maximum amount of time to spend on a single build */
|
||||
@ -77,6 +78,14 @@ public class ArbitraryDataBuildQueueItem extends ArbitraryDataResource {
|
||||
return this.buildStartTimestamp;
|
||||
}
|
||||
|
||||
public Integer getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
public void setPriority(Integer priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public void setFailed(boolean failed) {
|
||||
this.failed = failed;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class ArbitraryDataReader {
|
||||
* @param overwrite - set to true to force rebuild an existing cache
|
||||
* @return true if added or already present in queue; false if not
|
||||
*/
|
||||
public boolean loadAsynchronously(boolean overwrite) {
|
||||
public boolean loadAsynchronously(boolean overwrite, int priority) {
|
||||
ArbitraryDataCache cache = new ArbitraryDataCache(this.uncompressedPath, overwrite,
|
||||
this.resourceId, this.resourceIdType, this.service, this.identifier);
|
||||
if (cache.isCachedDataAvailable()) {
|
||||
@ -135,7 +135,9 @@ public class ArbitraryDataReader {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ArbitraryDataBuildManager.getInstance().addToBuildQueue(this.createQueueItem());
|
||||
ArbitraryDataBuildQueueItem item = this.createQueueItem();
|
||||
item.setPriority(priority);
|
||||
return ArbitraryDataBuildManager.getInstance().addToBuildQueue(item);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +76,7 @@ public class ArbitraryDataRenderer {
|
||||
if (!arbitraryDataReader.isCachedDataAvailable()) {
|
||||
// If async is requested, show a loading screen whilst build is in progress
|
||||
if (async) {
|
||||
arbitraryDataReader.loadAsynchronously(false);
|
||||
arbitraryDataReader.loadAsynchronously(false, 10);
|
||||
return this.getLoadingResponse(service, resourceId);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.qortal.repository.DataException;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@ -43,12 +44,13 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
||||
|
||||
ArbitraryDataBuildQueueItem queueItem = null;
|
||||
|
||||
// Find resources that are queued for building
|
||||
// Find resources that are queued for building (sorted by highest priority first)
|
||||
synchronized (buildManager.arbitraryDataBuildQueue) {
|
||||
Map.Entry<String, ArbitraryDataBuildQueueItem> next = buildManager.arbitraryDataBuildQueue
|
||||
.entrySet().stream()
|
||||
.filter(e -> e.getValue().isQueued())
|
||||
.findFirst().orElse(null);
|
||||
.sorted(Comparator.comparing(item -> item.getValue().getPriority()))
|
||||
.reduce((first, second) -> second).orElse(null);
|
||||
|
||||
if (next == null) {
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user