Skip to content

Commit

Permalink
Update to automatically delete any cached cover that has not been acc…
Browse files Browse the repository at this point in the history
…essed in 2 weeks or that was created more than 4 weeks ago
  • Loading branch information
mdnoble73 committed Jun 13, 2024
1 parent 20bf0a4 commit 2789680
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Binary file modified code/cron/cron.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.turning_leaf_technologies.cron;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.sql.Connection;
import java.util.Date;

Expand All @@ -17,6 +22,9 @@ public void doCronProcess(String servername, Ini configIni, Section processSetti
String coverPath = configIni.get("Site", "coverPath");
String[] coverPaths = new String[] { "/small", "/medium", "/large" };
long currentTime = new Date().getTime();
long oneWeekAgo = currentTime - (7L * 24 * 3600 * 1000);
long twoWeeksAgo = currentTime - (2L * 7 * 24 * 3600 * 1000);
long fourWeeksAgo = currentTime - (4L * 7 * 24 * 3600 * 1000);

//TODO: Get a smarter list of covers to remove
//Any default covers created more than a week ago
Expand All @@ -37,14 +45,29 @@ public void doCronProcess(String servername, Ini configIni, Section processSetti
if (filesToCheck != null) {
for (File curFile : filesToCheck) {
//Remove any files created more than 2 weeks ago.
if (curFile.lastModified() < (currentTime - 2 * 7 * 24 * 3600 * 1000)) {
if (curFile.delete()) {
numFilesDeleted++;
processLog.incUpdated();
} else {
processLog.incErrors("Unable to delete file " + curFile);
try {
BasicFileAttributes fileAttributes = Files.readAttributes(curFile.toPath(), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
FileTime dateCreated = fileAttributes.creationTime();
FileTime lastAccessed = fileAttributes.lastAccessTime();
if (lastAccessed.toMillis() < twoWeeksAgo) {
if (curFile.delete()) {
numFilesDeleted++;
processLog.incUpdated();
} else {
processLog.incErrors("Unable to delete file " + curFile);
}
}else if (dateCreated.toMillis() < fourWeeksAgo) {
if (curFile.delete()) {
numFilesDeleted++;
processLog.incUpdated();
} else {
processLog.incErrors("Unable to delete file " + curFile);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}

}
}
if (numFilesDeleted > 0) {
Expand Down
1 change: 1 addition & 0 deletions code/web/release_notes/24.06.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
- Remove some columns from the library table that were no longer in use. (*MDN*)
- When displaying reading history, check for blank formats. (Ticket 133712) (*MDN*)
- Optimize loading community translations. (Tickets 132412, 131255, 130103) (*MDN*)
- Update to automatically delete any cached cover that has not been accessed in 2 weeks or that was created more than 4 weeks ago. (*MDN*)

## This release includes code contributions from
- ByWater Solutions
Expand Down

0 comments on commit 2789680

Please sign in to comment.