implement autodeleting entries after <time>

This commit is contained in:
Tobias Fella 2020-03-26 20:24:28 +01:00
parent 399892d474
commit bd8ef20ecc
No known key found for this signature in database
GPG Key ID: E55EDAB3CA5D9925
3 changed files with 27 additions and 0 deletions

View File

@ -25,6 +25,7 @@ Kirigami.ScrollablePage {
settings.deleteAfterCount = deleteAfterCount.text
settings.deleteAfterType = deleteAfterType.currentIndex
settings.save()
pageStack.pop()
}
}
}

View File

@ -22,8 +22,10 @@
#include <QStandardPaths>
#include <QSqlError>
#include <QSqlDatabase>
#include <QDateTime>
#include "database.h"
#include "alligatorsettings.h"
#include "alligator-debug.h"
#define TRUE_OR_RETURN(x) if(!x) return false;
@ -40,6 +42,8 @@ Database::Database()
if(!migrate()) {
qCCritical(ALLIGATOR) << "Failed to migrate the database";
}
cleanup();
}
bool Database::migrate() {
@ -87,3 +91,24 @@ int Database::version() {
}
return -1;
}
void Database::cleanup() {
AlligatorSettings settings;
int count = settings.deleteAfterCount();
int type = settings.deleteAfterType();
if(type == 0) { // Delete after <count> posts per feed
//TODO
} else {
QDateTime dateTime = QDateTime::currentDateTime();
if(type == 1) dateTime.addDays(-count);
else if(type == 2) dateTime.addDays(-7*count);
else if(type == 3) dateTime.addMonths(-count);
qint64 sinceEpoch = dateTime.toSecsSinceEpoch();
QSqlQuery query;
query.prepare("DELETE FROM Entries WHERE updated < :sinceEpoch;");
query.bindValue(":sinceEpoch", sinceEpoch);
execute(query);
}
}

View File

@ -39,4 +39,5 @@ private:
bool migrate();
bool migrateTo1();
void cleanup();
};