mirror of https://github.com/M66B/FairEmail.git
Conditional contact cleanup
This commit is contained in:
parent
06af2bab49
commit
9fbc7ee94e
|
@ -94,6 +94,11 @@ public interface DaoContact {
|
|||
" GROUP BY name, email")
|
||||
List<EntityContact> searchContacts(Long account, Integer type, String query);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM contact" +
|
||||
" WHERE (type = " + EntityContact.TYPE_TO +
|
||||
" OR type = " + EntityContact.TYPE_FROM + ")")
|
||||
int countContacts();
|
||||
|
||||
@Insert
|
||||
long insertContact(EntityContact contact);
|
||||
|
||||
|
|
|
@ -51,7 +51,8 @@ public class WorkerCleanup extends Worker {
|
|||
private static final int CLEANUP_INTERVAL = 4; // hours
|
||||
private static final long KEEP_FILES_DURATION = 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_IMAGES_DURATION = 3 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_CONTACTS_DURATION = 180 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_CONTACTS_DURATION = 365 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final int KEEP_CONTACTS_COUNT = 10000;
|
||||
|
||||
private static Semaphore semaphore = new Semaphore(1);
|
||||
|
||||
|
@ -349,9 +350,11 @@ public class WorkerCleanup extends Worker {
|
|||
Log.i("Cleanup contacts");
|
||||
try {
|
||||
db.beginTransaction();
|
||||
int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION);
|
||||
int contacts = db.contact().countContacts();
|
||||
int deleted = (contacts < KEEP_CONTACTS_COUNT ? 0 :
|
||||
db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION));
|
||||
db.setTransactionSuccessful();
|
||||
Log.i("Deleted contacts=" + contacts);
|
||||
Log.i("Contacts=" + contacts + " deleted=" + deleted);
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue