From 6b7f37963cd7f7b3588afe2c81e8fc6fc5da6b60 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Mon, 10 Aug 2026 20:02:59 -0500 Subject: [PATCH] index.php: meta-refresh loading page while backfill is in progress --- index.php | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) 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. + ?> + + + + + Torn Vault Tracker — loading + + + + + +

Loading vault history…

+ +

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.

+ + +