diff --git a/index.php b/index.php index 8d77f6b..c307437 100644 --- a/index.php +++ b/index.php @@ -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. + ?> + + +
+ +Warning:
+ +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.
+ + +