diff --git a/functions.php b/functions.php index 6c9811f..abb86d8 100644 --- a/functions.php +++ b/functions.php @@ -102,6 +102,18 @@ function syncUserLogs($user) { $pdo = getDatabaseConnection(); + $stmt = $pdo->prepare('SELECT COUNT(*) FROM vault WHERE user = :user'); + $stmt->bindValue(':user', $user); + $stmt->execute(); + $userRowCount = (int)$stmt->fetchColumn(); + + // If the user has zero rows (not the global dbNew, but per-user empty), + // delegate to backfillUserLogs which walks the full prev chain. + if ($userRowCount === 0) { + backfillUserLogs($user); + return; + } + $stmt = $pdo->prepare('SELECT MAX(timestamp) AS max_ts FROM vault WHERE user = :user'); $stmt->bindValue(':user', $user); $stmt->execute();