forked from Qortal/qortal
Arbitrary data manager now only prefetches data according to the storage policy.
- If storage policy includes "FOLLOWING", only process transactions relating to the followed names. - If storage policy is "ALL", process all transactions. - If storage policy is "NONE" or "VIEWED", don't process or prefetch any data.
This commit is contained in:
parent
abfeafc823
commit
a61b0685f0
@ -9,6 +9,7 @@ import org.qortal.controller.Controller;
|
||||
import org.qortal.data.network.ArbitraryPeerData;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData;
|
||||
import org.qortal.data.transaction.TransactionData;
|
||||
import org.qortal.list.ResourceListManager;
|
||||
import org.qortal.network.Network;
|
||||
import org.qortal.network.Peer;
|
||||
import org.qortal.network.message.*;
|
||||
@ -89,13 +90,6 @@ public class ArbitraryDataManager extends Thread {
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Manager");
|
||||
|
||||
// Keep a reference to the storage manager as we will need this a lot
|
||||
ArbitraryDataStorageManager storageManager = ArbitraryDataStorageManager.getInstance();
|
||||
|
||||
// Paginate queries when fetching arbitrary transactions
|
||||
final int limit = 100;
|
||||
int offset = 0;
|
||||
|
||||
try {
|
||||
while (!isStopping) {
|
||||
Thread.sleep(2000);
|
||||
@ -110,13 +104,67 @@ public class ArbitraryDataManager extends Thread {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch data according to storage policy
|
||||
switch (Settings.getInstance().getStoragePolicy()) {
|
||||
case FOLLOWED:
|
||||
case FOLLOWED_AND_VIEWED:
|
||||
this.processNames();
|
||||
break;
|
||||
|
||||
case ALL:
|
||||
this.processAll();
|
||||
|
||||
case NONE:
|
||||
case VIEWED:
|
||||
default:
|
||||
// Nothing to fetch in advance
|
||||
Thread.sleep(60000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Fall-through to exit thread...
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
isStopping = true;
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
private void processNames() {
|
||||
// Fetch latest list of followed names
|
||||
List<String> followedNames = ResourceListManager.getInstance().getStringsInList("followed", "names");
|
||||
if (followedNames == null || followedNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through the names in the list and fetch transactions for each
|
||||
for (String name : followedNames) {
|
||||
this.fetchAndProcessTransactions(name);
|
||||
}
|
||||
}
|
||||
|
||||
private void processAll() {
|
||||
this.fetchAndProcessTransactions(null);
|
||||
}
|
||||
|
||||
private void fetchAndProcessTransactions(String name) {
|
||||
ArbitraryDataStorageManager storageManager = ArbitraryDataStorageManager.getInstance();
|
||||
|
||||
// Paginate queries when fetching arbitrary transactions
|
||||
final int limit = 100;
|
||||
int offset = 0;
|
||||
|
||||
while (!isStopping) {
|
||||
|
||||
// Any arbitrary transactions we want to fetch data for?
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, ARBITRARY_TX_TYPE, null, null, null, ConfirmationStatus.BOTH, limit, offset, true);
|
||||
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, ARBITRARY_TX_TYPE, null, name, null, ConfirmationStatus.BOTH, limit, offset, true);
|
||||
// LOGGER.info("Found {} arbitrary transactions at offset: {}, limit: {}", signatures.size(), offset, limit);
|
||||
if (signatures == null || signatures.isEmpty()) {
|
||||
offset = 0;
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
offset += limit;
|
||||
|
||||
@ -139,8 +187,7 @@ public class ArbitraryDataManager extends Thread {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Transaction has no name associated with it
|
||||
if (!storageManager.shouldStoreDataWithoutName()) {
|
||||
iterator.remove();
|
||||
@ -186,14 +233,6 @@ public class ArbitraryDataManager extends Thread {
|
||||
LOGGER.error("Repository issue when fetching arbitrary transaction data", e);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Fall-through to exit thread...
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
isStopping = true;
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
private ArbitraryTransaction fetchTransaction(final Repository repository, byte[] signature) {
|
||||
|
@ -161,6 +161,10 @@ public class ResourceList {
|
||||
return this.resourceName;
|
||||
}
|
||||
|
||||
public List<String> getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s %s", this.category, this.resourceName);
|
||||
}
|
||||
|
@ -125,4 +125,12 @@ public class ResourceListManager {
|
||||
return list.getJSONString();
|
||||
}
|
||||
|
||||
public List<String> getStringsInList(String category, String resourceName) {
|
||||
ResourceList list = this.getList(category, resourceName);
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
return list.getList();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user