index.php: meta-refresh loading page while backfill is in progress

This commit is contained in:
Keith Solomon
2026-08-10 20:02:59 -05:00
parent a9a635e172
commit 6b7f37963c
+36 -9
View File
@@ -14,22 +14,49 @@ require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php'; require_once __DIR__ . '/functions.php';
$bootstrapWarning = null; $bootstrapWarning = null;
$needsBackfill = false;
try { try {
if (dbNew()) { foreach (USER_KEYS as $key => $value) {
foreach (USER_KEYS as $key => $value) { syncUserLogs($key);
backfillUserLogs($key); // If the sync didn't populate this user, backfill is still needed.
} $pdo = getDatabaseConnection();
header('Location: /'); $stmt = $pdo->prepare('SELECT COUNT(*) FROM vault WHERE user = :user');
exit; $stmt->bindValue(':user', $key);
} else { $stmt->execute();
foreach (USER_KEYS as $key => $value) { if ((int)$stmt->fetchColumn() === 0) {
syncUserLogs($key); $needsBackfill = true;
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
$bootstrapWarning = $e->getMessage(); $bootstrapWarning = $e->getMessage();
} }
if ($needsBackfill) {
// Heavy work remains. Return a loading page that auto-refreshes;
// each refresh does another page of API fetches.
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Torn Vault Tracker &mdash; loading</title>
<meta http-equiv="refresh" content="3">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="style.css?v=<?php echo filemtime('style.css'); ?>">
</head>
<body>
<h1>Loading vault history&hellip;</h1>
<?php if ($bootstrapWarning !== null): ?>
<p>Warning: <?php echo htmlspecialchars($bootstrapWarning, ENT_QUOTES, 'UTF-8'); ?></p>
<?php endif; ?>
<p>One-time backfill in progress. The Torn API returns up to 100 vault entries per call;
we'll keep fetching until your full history is loaded. This page will refresh automatically.</p>
</body>
</html>
<?php
exit;
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>