<?php
require_once __DIR__ . '/../includes/functions.php';
startSecureSession();
requireAdmin();

$db = getDB();

// Get all tables
$tables = [];
$stmt = $db->query("SHOW TABLES");
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
    $tables[] = $row[0];
}

if (!empty($tables)) {
    $tableList = implode(', ', $tables);
    $db->query("OPTIMIZE TABLE $tableList");
}

header('Location: dashboard.php?msg=optimized');
exit;
