mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 16:43:26 +02:00
Moved cleaning up image cache to daily job
This commit is contained in:
@@ -134,7 +134,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
enum ViewType {UNIFIED, FOLDER, THREAD, SEARCH}
|
||||
|
||||
private static final float LOW_LIGHT = 0.6f;
|
||||
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L;
|
||||
|
||||
private static DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG);
|
||||
|
||||
@@ -786,17 +785,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
|
||||
// Get cache folder
|
||||
File dir = new File(context.getCacheDir(), "images");
|
||||
dir.mkdir();
|
||||
|
||||
// Cleanup cache
|
||||
long now = new Date().getTime();
|
||||
File[] images = dir.listFiles();
|
||||
if (images != null)
|
||||
for (File image : images)
|
||||
if (image.isFile() && image.lastModified() + CACHE_IMAGE_DURATION < now) {
|
||||
Log.i(Helper.TAG, "Deleting from image cache " + image.getName());
|
||||
image.delete();
|
||||
}
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
|
||||
InputStream is = null;
|
||||
FileOutputStream os = null;
|
||||
|
||||
@@ -79,7 +79,8 @@ public class EntityAttachment {
|
||||
|
||||
static File getFile(Context context, Long id) {
|
||||
File dir = new File(context.getFilesDir(), "attachments");
|
||||
dir.mkdir();
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return new File(dir, Long.toString(id));
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,8 @@ public class EntityMessage implements Serializable {
|
||||
|
||||
static File getFile(Context context, Long id) {
|
||||
File dir = new File(context.getFilesDir(), "messages");
|
||||
dir.mkdir();
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return new File(dir, id.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ public class JobDaily extends JobService {
|
||||
private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||
|
||||
private static final long CLEANUP_INTERVAL = 4 * 3600 * 1000L; // milliseconds
|
||||
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L;
|
||||
|
||||
public static void schedule(Context context) {
|
||||
Log.i(Helper.TAG, "Scheduling daily job");
|
||||
@@ -121,6 +122,18 @@ public class JobDaily extends JobService {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup cached images
|
||||
Log.i(Helper.TAG, "Cleanup cached image files");
|
||||
long now = new Date().getTime();
|
||||
File[] images = new File(context.getCacheDir(), "images").listFiles();
|
||||
if (images != null)
|
||||
for (File file : images)
|
||||
if (file.isFile() && file.lastModified() + CACHE_IMAGE_DURATION < now) {
|
||||
Log.i(Helper.TAG, "Deleting cached image=" + file.getName());
|
||||
if (!file.delete())
|
||||
Log.w(Helper.TAG, "Error deleting " + file);
|
||||
}
|
||||
|
||||
Log.i(Helper.TAG, "Cleanup log");
|
||||
long before = new Date().getTime() - 24 * 3600 * 1000L;
|
||||
int logs = db.log().deleteLogs(before);
|
||||
|
||||
Reference in New Issue
Block a user