From a6f31af021b5149cc6a33efed69a64c8e06ddceb Mon Sep 17 00:00:00 2001 From: Denghui Dong Date: Sat, 21 Oct 2023 16:23:22 +0800 Subject: [PATCH] chore: modify the threshold of StorageRelatedTasks and add file deletion log --- .../eclipse/jifa/server/service/impl/FileServiceImpl.java | 8 +++++++- .../org/eclipse/jifa/server/task/StorageRelatedTasks.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/eclipse/jifa/server/service/impl/FileServiceImpl.java b/server/src/main/java/org/eclipse/jifa/server/service/impl/FileServiceImpl.java index 0cd1b7b3..464a9984 100644 --- a/server/src/main/java/org/eclipse/jifa/server/service/impl/FileServiceImpl.java +++ b/server/src/main/java/org/eclipse/jifa/server/service/impl/FileServiceImpl.java @@ -59,6 +59,7 @@ import java.nio.file.Path; import java.time.Instant; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -286,7 +287,12 @@ public NamedResource handleDownloadRequest(long fileId) throws Throwable { @Override public void deleteOldestFile() { - fileRepo.findFirstByOrderByCreatedTimeDesc().ifPresent(this::doDelete); + Optional optional = fileRepo.findFirstByOrderByCreatedTimeDesc(); + if (optional.isPresent()) { + FileEntity file = optional.get(); + doDelete(file); + log.info("File '{} ({})' is deleted", file.getOriginalName(), file.getUniqueName()); + } } private FileEntity getFileEntityByIdAndCheckAuthority(long id) { diff --git a/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java b/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java index 4c16c5ac..55bbd2cc 100644 --- a/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java +++ b/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java @@ -44,7 +44,7 @@ public class StorageRelatedTasks extends ConfigurationAccessor { private final StorageService storageService; - private static final double THRESHOLD = 0.15; + private static final double THRESHOLD = 0.05; public StorageRelatedTasks(LockSupport lockSupport, FileRepo fileRepo,