mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-31 20:25:38 +00:00
Batch delete log entries
This commit is contained in:
parent
d4400bca9d
commit
212a78e638
3 changed files with 19 additions and 5 deletions
|
@ -42,6 +42,7 @@ public interface DaoLog {
|
|||
long insertLog(EntityLog log);
|
||||
|
||||
@Query("DELETE FROM log" +
|
||||
" WHERE time < :before")
|
||||
int deleteLogs(long before);
|
||||
" WHERE id IN (SELECT id FROM log" +
|
||||
" WHERE time < :before ORDER BY time LIMIT :limit)")
|
||||
int deleteLogs(long before, int limit);
|
||||
}
|
||||
|
|
|
@ -136,7 +136,13 @@ public class FragmentLogs extends FragmentBase {
|
|||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
db.log().deleteLogs(new Date().getTime());
|
||||
long before = new Date().getTime();
|
||||
while (true) {
|
||||
int logs = db.log().deleteLogs(before, WorkerCleanup.LOG_DELETE_BATCH_SIZE);
|
||||
Log.i("Deleted logs=" + logs);
|
||||
if (logs < WorkerCleanup.LOG_DELETE_BATCH_SIZE)
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ public class WorkerCleanup extends Worker {
|
|||
private static final long KEEP_CONTACTS_DURATION = 180 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_LOG_DURATION = 24 * 3600 * 1000L; // milliseconds
|
||||
|
||||
static final int LOG_DELETE_BATCH_SIZE = 100;
|
||||
|
||||
public WorkerCleanup(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||
super(context, workerParams);
|
||||
Log.i("Instance " + getName());
|
||||
|
@ -297,8 +299,13 @@ public class WorkerCleanup extends Worker {
|
|||
Log.i("Deleted contacts=" + contacts);
|
||||
|
||||
Log.i("Cleanup log");
|
||||
int logs = db.log().deleteLogs(now - KEEP_LOG_DURATION);
|
||||
Log.i("Deleted logs=" + logs);
|
||||
long before = now - KEEP_LOG_DURATION;
|
||||
while (true) {
|
||||
int logs = db.log().deleteLogs(before, LOG_DELETE_BATCH_SIZE);
|
||||
Log.i("Deleted logs=" + logs + " before=" + new Date(before));
|
||||
if (logs < LOG_DELETE_BATCH_SIZE)
|
||||
break;
|
||||
}
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
// https://sqlite.org/lang_analyze.html
|
||||
|
|
Loading…
Reference in a new issue