fixing db bugs
Deploy / deploy (push) Successful in 9s

This commit is contained in:
2026-05-16 12:38:42 +02:00
parent 0c3b75d7a8
commit 78eb0e8430
+16 -10
View File
@@ -136,11 +136,11 @@ class Repository
}
if ($since) {
$where[] = 'created_at >= ?';
$params[] = $since;
$params[] = str_replace('T', ' ', $since);
}
if ($until) {
$where[] = 'created_at <= ?';
$params[] = $until;
$params[] = str_replace('T', ' ', $until);
}
$sql = "SELECT * FROM alerts";
@@ -207,11 +207,11 @@ class Repository
if ($since) {
$where[] = 'e.created_at >= ?';
$params[] = $since;
$params[] = str_replace('T', ' ', $since);
}
if ($until) {
$where[] = 'e.created_at <= ?';
$params[] = $until;
$params[] = str_replace('T', ' ', $until);
}
if ($query === '*') {
@@ -382,22 +382,28 @@ class Repository
public function getAuditLog(int $limit = 50): array
{
return $this->db->pdo()->prepare(
$stmt = $this->db->pdo()->prepare(
"SELECT * FROM audit_log ORDER BY created_at DESC LIMIT ?"
)->execute([$limit])->fetchAll();
);
$stmt->execute([$limit]);
return $stmt->fetchAll();
}
// --- Retention ---
public function purgeOldData(int $logDays = 30, int $alertDays = 90): array
{
$deletedLogs = $this->db->pdo()->prepare(
$stmt = $this->db->pdo()->prepare(
"DELETE FROM log_entries WHERE created_at < datetime('now', ?)"
)->execute(['-' . $logDays . ' days'])->rowCount();
);
$stmt->execute(['-' . $logDays . ' days']);
$deletedLogs = $stmt->rowCount();
$deletedAlerts = $this->db->pdo()->prepare(
$stmt = $this->db->pdo()->prepare(
"DELETE FROM alerts WHERE status = 'resolved' AND created_at < datetime('now', ?)"
)->execute(['-' . $alertDays . ' days'])->rowCount();
);
$stmt->execute(['-' . $alertDays . ' days']);
$deletedAlerts = $stmt->rowCount();
$this->db->pdo()->exec("DELETE FROM rate_limiter WHERE window_start < " . (time() - 86400));