Improved cache clearing process and logging.

This commit is contained in:
CalDescent 2022-01-21 13:32:59 +00:00
parent 85c61c1bc1
commit 6e91157dcf
4 changed files with 21 additions and 7 deletions

View File

@ -1,5 +1,7 @@
package org.qortal.arbitrary; package org.qortal.arbitrary;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType; import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
import org.qortal.arbitrary.misc.Service; import org.qortal.arbitrary.misc.Service;
import org.qortal.controller.arbitrary.ArbitraryDataBuildManager; import org.qortal.controller.arbitrary.ArbitraryDataBuildManager;
@ -25,6 +27,8 @@ import static org.qortal.data.arbitrary.ArbitraryResourceStatus.Status;
public class ArbitraryDataResource { public class ArbitraryDataResource {
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataResource.class);
protected final String resourceId; protected final String resourceId;
protected final ResourceIdType resourceIdType; protected final ResourceIdType resourceIdType;
protected final Service service; protected final Service service;
@ -124,7 +128,10 @@ public class ArbitraryDataResource {
String identifier = this.identifier != null ? this.identifier : "default"; String identifier = this.identifier != null ? this.identifier : "default";
Path cachePath = Paths.get(baseDir, "reader", this.resourceIdType.toString(), this.resourceId, this.service.toString(), identifier); Path cachePath = Paths.get(baseDir, "reader", this.resourceIdType.toString(), this.resourceId, this.service.toString(), identifier);
if (cachePath.toFile().exists()) { if (cachePath.toFile().exists()) {
FilesystemUtils.safeDeleteDirectory(cachePath, true); boolean success = FilesystemUtils.safeDeleteDirectory(cachePath, true);
if (success) {
LOGGER.info("Cleared cache for resource {}", this.toString());
}
} }
} }

View File

@ -242,7 +242,7 @@ public class ArbitraryDataFileListManager {
return ArbitraryDataFileManager.getInstance().fetchDataFilesFromPeersForSignature(signature); return ArbitraryDataFileManager.getInstance().fetchDataFilesFromPeersForSignature(signature);
} }
LOGGER.debug("Skipping file list request for signature {} due to rate limit", signature58); LOGGER.trace("Skipping file list request for signature {} due to rate limit", signature58);
return false; return false;
} }
this.addToSignatureRequests(signature58, true, false); this.addToSignatureRequests(signature58, true, false);

View File

@ -338,7 +338,7 @@ public class ArbitraryDataManager extends Thread {
ArbitraryDataResource resource = ArbitraryDataResource resource =
new ArbitraryDataResource(resourceId, ArbitraryDataFile.ResourceIdType.NAME, service, identifier); new ArbitraryDataResource(resourceId, ArbitraryDataFile.ResourceIdType.NAME, service, identifier);
String key = resource.getUniqueKey(); String key = resource.getUniqueKey();
LOGGER.info("Clearing cache for {}...", resource); LOGGER.trace("Clearing cache for {}...", resource);
if (this.arbitraryDataCachedResources.containsKey(key)) { if (this.arbitraryDataCachedResources.containsKey(key)) {
this.arbitraryDataCachedResources.remove(key); this.arbitraryDataCachedResources.remove(key);

View File

@ -150,17 +150,24 @@ public class FilesystemUtils {
} }
} }
public static void safeDeleteDirectory(Path path, boolean cleanup) throws IOException { public static boolean safeDeleteDirectory(Path path, boolean cleanup) throws IOException {
boolean success = false;
// Delete path, if it exists in our data/temp directory // Delete path, if it exists in our data/temp directory
if (FilesystemUtils.pathInsideDataOrTempPath(path)) { if (FilesystemUtils.pathInsideDataOrTempPath(path)) {
if (Files.exists(path)) {
File directory = new File(path.toString()); File directory = new File(path.toString());
FileUtils.deleteDirectory(directory); FileUtils.deleteDirectory(directory);
success = true;
}
} }
if (cleanup) { if (success && cleanup) {
// Delete the parent directories if they are empty (and exist in our data/temp directory) // Delete the parent directories if they are empty (and exist in our data/temp directory)
FilesystemUtils.safeDeleteEmptyParentDirectories(path); FilesystemUtils.safeDeleteEmptyParentDirectories(path);
} }
return success;
} }
public static void safeDeleteEmptyParentDirectories(Path path) throws IOException { public static void safeDeleteEmptyParentDirectories(Path path) throws IOException {