Browse Source

Cleanup message & attachment files

main
M66B 6 years ago
parent
commit
ae8eb762f8
3 changed files with 38 additions and 3 deletions
  1. +6
    -1
      app/src/main/java/eu/faircode/email/DaoAttachment.java
  2. +12
    -2
      app/src/main/java/eu/faircode/email/DaoMessage.java
  3. +20
    -0
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 6
- 1
app/src/main/java/eu/faircode/email/DaoAttachment.java View File

@ -34,11 +34,16 @@ public interface DaoAttachment {
" ORDER BY sequence")
LiveData<List<EntityAttachment>> liveAttachments(long id);
@Query("SELECT COUNT(attachment.id)" +
@Query("SELECT COUNT(id)" +
" FROM attachment" +
" WHERE message = :message")
int getAttachmentCount(long message);
@Query("SELECT COUNT(id)" +
" FROM attachment" +
" WHERE id = :id")
int countAttachment(long id);
@Query("SELECT * FROM attachment" +
" WHERE message = :message" +
" ORDER BY sequence")


+ 12
- 2
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -74,10 +74,20 @@ public interface DaoMessage {
" ORDER BY message.received DESC, message.sent DESC")
DataSource.Factory<Integer, TupleMessageEx> pagedThread(long msgid, boolean debug);
@Query("SELECT * FROM message WHERE id = :id")
@Query("SELECT *" +
" FROM message" +
" WHERE id = :id")
EntityMessage getMessage(long id);
@Query("SELECT * FROM message WHERE folder = :folder AND uid = :uid")
@Query("SELECT COUNT(id)" +
" FROM message" +
" WHERE id = :id")
int countMessage(long id);
@Query("SELECT *" +
" FROM message" +
" WHERE folder = :folder" +
" AND uid = :uid")
EntityMessage getMessageByUid(long folder, long uid);
@Query("SELECT message.* FROM message" +


+ 20
- 0
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -1183,6 +1183,26 @@ public class ServiceSynchronize extends LifecycleService {
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
}
// Cleanup files
File messages = new File(getFilesDir(), "messages");
for (File file : messages.listFiles())
if (file.isFile()) {
long id = Long.parseLong(file.getName());
if (db.message().countMessage(id) == 0) {
Log.i(Helper.TAG, "Cleanup message id=" + id);
file.delete();
}
}
File attachments = new File(getFilesDir(), "attachments");
for (File file : attachments.listFiles())
if (file.isFile()) {
long id = Long.parseLong(file.getName());
if (db.attachment().countAttachment(id) == 0) {
Log.i(Helper.TAG, "Cleanup attachment id=" + id);
file.delete();
}
}
Log.w(Helper.TAG, folder.name + " statistics added=" + added + " updated=" + updated + " unchanged=" + unchanged);
} finally {
Log.v(Helper.TAG, folder.name + " end sync");


Loading…
Cancel
Save