Refactor to simplify some duplicated code

This commit is contained in:
CalDescent 2021-11-03 21:39:02 +00:00
parent 6d031130b9
commit d7ddcda9da
3 changed files with 13 additions and 26 deletions

View File

@ -138,20 +138,11 @@ public class ArbitraryDataCleanupManager extends Thread {
// Check to see if we should be hosting data for this transaction at all
if (arbitraryTransactionData.getName() != null) {
if (!storageManager.shouldStoreDataForName(arbitraryTransactionData.getName())) {
LOGGER.info("Deleting transaction {} because we are no longer storing data for name {}",
Base58.encode(arbitraryTransactionData.getSignature()), arbitraryTransactionData.getName());
ArbitraryTransactionUtils.deleteCompleteFileAndChunks(arbitraryTransactionData);
continue;
}
}
else {
// Transaction has no name associated with it
if (!storageManager.shouldStoreDataWithoutName()) {
ArbitraryTransactionUtils.deleteCompleteFileAndChunks(arbitraryTransactionData);
continue;
}
if (!storageManager.shouldStoreDataForName(arbitraryTransactionData.getName())) {
LOGGER.info("Deleting transaction {} because we are no longer storing data for name {}",
Base58.encode(arbitraryTransactionData.getSignature()), arbitraryTransactionData.getName());
ArbitraryTransactionUtils.deleteCompleteFileAndChunks(arbitraryTransactionData);
continue;
}
// Check to see if we have had a more recent PUT

View File

@ -182,17 +182,9 @@ public class ArbitraryDataManager extends Thread {
ArbitraryTransactionData arbitraryTransactionData = (ArbitraryTransactionData) arbitraryTransaction.getTransactionData();
// Skip transactions that we don't need to store data for
if (arbitraryTransactionData.getName() != null) {
if (!storageManager.shouldStoreDataForName(arbitraryTransactionData.getName())) {
iterator.remove();
continue;
}
} else {
// Transaction has no name associated with it
if (!storageManager.shouldStoreDataWithoutName()) {
iterator.remove();
continue;
}
if (!storageManager.shouldStoreDataForName(arbitraryTransactionData.getName())) {
iterator.remove();
continue;
}
// Remove transactions that we already have local data for

View File

@ -26,6 +26,10 @@ public class ArbitraryDataStorageManager {
}
public boolean shouldStoreDataForName(String name) {
if (name == null) {
return this.shouldStoreDataWithoutName();
}
switch (Settings.getInstance().getStoragePolicy()) {
case FOLLOWED:
case FOLLOWED_AND_VIEWED:
@ -41,7 +45,7 @@ public class ArbitraryDataStorageManager {
}
}
public boolean shouldStoreDataWithoutName() {
private boolean shouldStoreDataWithoutName() {
switch (Settings.getInstance().getStoragePolicy()) {
case ALL:
return true;