index.php: meta-refresh loading page while backfill is in progress
This commit is contained in:
@@ -14,22 +14,49 @@ require_once __DIR__ . '/config.php';
|
||||
require_once __DIR__ . '/functions.php';
|
||||
|
||||
$bootstrapWarning = null;
|
||||
$needsBackfill = false;
|
||||
|
||||
try {
|
||||
if (dbNew()) {
|
||||
foreach (USER_KEYS as $key => $value) {
|
||||
backfillUserLogs($key);
|
||||
}
|
||||
header('Location: /');
|
||||
exit;
|
||||
} else {
|
||||
foreach (USER_KEYS as $key => $value) {
|
||||
syncUserLogs($key);
|
||||
foreach (USER_KEYS as $key => $value) {
|
||||
syncUserLogs($key);
|
||||
// If the sync didn't populate this user, backfill is still needed.
|
||||
$pdo = getDatabaseConnection();
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM vault WHERE user = :user');
|
||||
$stmt->bindValue(':user', $key);
|
||||
$stmt->execute();
|
||||
if ((int)$stmt->fetchColumn() === 0) {
|
||||
$needsBackfill = true;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$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 — 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…</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>
|
||||
|
||||
Reference in New Issue
Block a user