forked from Qortal/qortal
Added hosted transactions cache
This skips the need to check the filesystem if no new files have arrived since the last lookup.
This commit is contained in:
parent
89d08ca359
commit
8bb3a3f8a6
@ -703,6 +703,9 @@ public class ArbitraryDataManager extends Thread {
|
||||
repository.discardChanges();
|
||||
repository.getArbitraryRepository().save(arbitraryPeerData);
|
||||
repository.saveChanges();
|
||||
|
||||
// Invalidate the hosted transactions cache as we are now hosting something new
|
||||
ArbitraryDataStorageManager.getInstance().invalidateHostedTransactionsCache();
|
||||
}
|
||||
|
||||
// Check if we have all the files we need for this transaction
|
||||
|
@ -41,6 +41,8 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
private long totalDirectorySize = 0L;
|
||||
private long lastDirectorySizeCheck = 0;
|
||||
|
||||
private List<ArbitraryTransactionData> hostedTransactions;
|
||||
|
||||
private static long DIRECTORY_SIZE_CHECK_INTERVAL = 10 * 60 * 1000L; // 10 minutes
|
||||
|
||||
/** Treat storage as full at 90% usage, to reduce risk of going over the limit.
|
||||
@ -219,6 +221,11 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
// Hosted data
|
||||
|
||||
public List<ArbitraryTransactionData> listAllHostedTransactions(Repository repository) throws IOException {
|
||||
// Load from cache if we can, to avoid disk reads
|
||||
if (this.hostedTransactions != null) {
|
||||
return this.hostedTransactions;
|
||||
}
|
||||
|
||||
List<ArbitraryTransactionData> arbitraryTransactionDataList = new ArrayList<>();
|
||||
|
||||
Path dataPath = Paths.get(Settings.getInstance().getDataPath());
|
||||
@ -254,9 +261,16 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
// Update cache
|
||||
this.hostedTransactions = arbitraryTransactionDataList;
|
||||
|
||||
return arbitraryTransactionDataList;
|
||||
}
|
||||
|
||||
public void invalidateHostedTransactionsCache() {
|
||||
this.hostedTransactions = null;
|
||||
}
|
||||
|
||||
|
||||
// Size limits
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user