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:
CalDescent 2021-12-04 09:28:45 +00:00
parent 89d08ca359
commit 8bb3a3f8a6
2 changed files with 17 additions and 0 deletions

View File

@ -703,6 +703,9 @@ public class ArbitraryDataManager extends Thread {
repository.discardChanges(); repository.discardChanges();
repository.getArbitraryRepository().save(arbitraryPeerData); repository.getArbitraryRepository().save(arbitraryPeerData);
repository.saveChanges(); 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 // Check if we have all the files we need for this transaction

View File

@ -41,6 +41,8 @@ public class ArbitraryDataStorageManager extends Thread {
private long totalDirectorySize = 0L; private long totalDirectorySize = 0L;
private long lastDirectorySizeCheck = 0; private long lastDirectorySizeCheck = 0;
private List<ArbitraryTransactionData> hostedTransactions;
private static long DIRECTORY_SIZE_CHECK_INTERVAL = 10 * 60 * 1000L; // 10 minutes 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. /** 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 // Hosted data
public List<ArbitraryTransactionData> listAllHostedTransactions(Repository repository) throws IOException { 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<>(); List<ArbitraryTransactionData> arbitraryTransactionDataList = new ArrayList<>();
Path dataPath = Paths.get(Settings.getInstance().getDataPath()); Path dataPath = Paths.get(Settings.getInstance().getDataPath());
@ -254,9 +261,16 @@ public class ArbitraryDataStorageManager extends Thread {
} }
} }
// Update cache
this.hostedTransactions = arbitraryTransactionDataList;
return arbitraryTransactionDataList; return arbitraryTransactionDataList;
} }
public void invalidateHostedTransactionsCache() {
this.hostedTransactions = null;
}
// Size limits // Size limits