112 lines
4.5 KiB
PHP
112 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* C-Relay-PG Admin — Inbox Queue Monitor.
|
|
*/
|
|
require_once __DIR__ . '/lib/helpers.php';
|
|
|
|
$pdo = db();
|
|
|
|
$stats = $pdo->query("
|
|
SELECT
|
|
COUNT(*) AS pending,
|
|
COUNT(*) FILTER (WHERE source_class = 'live') AS live,
|
|
COUNT(*) FILTER (WHERE source_class = 'backfill') AS backfill,
|
|
COUNT(*) FILTER (WHERE source_class = 'discovery') AS discovery,
|
|
COUNT(*) FILTER (WHERE priority = 0) AS high_priority,
|
|
COALESCE(EXTRACT(EPOCH FROM NOW())::BIGINT - MIN(received_at), 0) AS oldest_age
|
|
FROM caching_event_inbox
|
|
")->fetch() ?: ['pending' => 0, 'live' => 0, 'backfill' => 0, 'discovery' => 0, 'high_priority' => 0, 'oldest_age' => 0];
|
|
|
|
$recent = $pdo->query("
|
|
SELECT event_id, event_json->>'pubkey' AS pubkey, event_json->>'kind' AS kind,
|
|
source_relay, source_class, priority, received_at
|
|
FROM caching_event_inbox
|
|
ORDER BY received_at DESC
|
|
LIMIT 20
|
|
")->fetchAll();
|
|
|
|
admin_header('inbox', 'C-Relay-PG Admin — Inbox');
|
|
?>
|
|
|
|
<div class="section">
|
|
<div class="section-header">INBOX QUEUE MONITOR</div>
|
|
|
|
<div class="cards">
|
|
<div class="card">
|
|
<div class="label">Pending Events</div>
|
|
<div class="value" id="inbox-pending"><?= number_format(intval($stats['pending'])) ?></div>
|
|
<div class="sub" id="inbox-detail"><?= intval($stats['live']) ?> live, <?= intval($stats['backfill']) ?> backfill, <?= intval($stats['discovery']) ?> discovery</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="label">High Priority</div>
|
|
<div class="value"><?= number_format(intval($stats['high_priority'])) ?></div>
|
|
<div class="sub">priority = 0 (live events)</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="label">Oldest Pending</div>
|
|
<div class="value" id="inbox-oldest"><?= intval($stats['oldest_age']) ?>s</div>
|
|
<div class="sub">age of oldest event in queue</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (intval($stats['oldest_age']) > 300): ?>
|
|
<p class="status-error" style="padding:10px;border:1px solid var(--accent-color);border-radius:5px;margin-bottom:16px">
|
|
⚠ Oldest pending event is <?= intval($stats['oldest_age']) ?>s old — the inbox poller may not be keeping up.
|
|
Check that <code>caching_inbox_enabled = true</code> in the config table and the relay is running.
|
|
</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<div class="section-header">RECENT EVENTS IN QUEUE (last 20)</div>
|
|
<div class="config-table-container">
|
|
<table class="config-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Event ID</th>
|
|
<th>Pubkey</th>
|
|
<th>Kind</th>
|
|
<th>Source Relay</th>
|
|
<th>Class</th>
|
|
<th>Priority</th>
|
|
<th>Received</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($recent as $r): ?>
|
|
<tr>
|
|
<td class="pubkey"><?= e(trunc($r['event_id'], 16)) ?></td>
|
|
<td class="pubkey"><?= e(trunc($r['pubkey'], 16)) ?></td>
|
|
<td><?= e($r['kind']) ?></td>
|
|
<td><?= e($r['source_relay'] ?? '—') ?></td>
|
|
<td><span class="badge badge-muted"><?= e($r['source_class']) ?></span></td>
|
|
<td><?= intval($r['priority']) ?></td>
|
|
<td><?= time_ago(intval($r['received_at'])) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($recent)): ?>
|
|
<tr><td colspan="7" style="text-align:center;color:var(--muted-color);padding:20px">Inbox is empty — all events have been dequeued.</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
async function refreshInbox() {
|
|
try {
|
|
const res = await fetch('api/status.php');
|
|
if (!res.ok) return;
|
|
const d = await res.json();
|
|
console.log('[inbox] refreshed at', new Date().toLocaleTimeString(), '— pending:', d.inbox_pending);
|
|
const p = document.getElementById('inbox-pending');
|
|
const det = document.getElementById('inbox-detail');
|
|
if (p) p.textContent = (d.inbox_pending ?? 0).toLocaleString();
|
|
if (det) det.textContent = (d.inbox_live ?? 0) + ' live, ' + (d.inbox_backfill ?? 0) + ' backfill';
|
|
} catch (e) {}
|
|
}
|
|
setInterval(refreshInbox, <?= cfg('refresh_ms', 10000) ?>);
|
|
</script>
|
|
|
|
<?php admin_footer(); ?>
|