100 lines
4.4 KiB
PHP
100 lines
4.4 KiB
PHP
<?php
|
|
/**
|
|
* C-Relay-PG Admin — Caching Config Editor.
|
|
* On save, bumps caching_config_generation so the caching service hot-reloads.
|
|
*/
|
|
require_once __DIR__ . '/lib/helpers.php';
|
|
|
|
$pdo = db();
|
|
$message = '';
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$fields = [
|
|
'caching_root_npubs', 'caching_bootstrap_relays', 'caching_kinds',
|
|
'caching_admin_kinds', 'caching_live_enabled', 'caching_backfill_enabled',
|
|
'caching_backfill_page_size', 'caching_backfill_tick_interval_ms',
|
|
'caching_follow_graph_refresh_seconds', 'caching_relay_discovery_refresh_seconds',
|
|
'caching_max_followed_pubkeys', 'caching_max_upstream_relays',
|
|
'caching_max_relays_per_pubkey', 'caching_query_timeout_ms',
|
|
'caching_live_resubscribe_seconds',
|
|
];
|
|
try {
|
|
$pdo->beginTransaction();
|
|
foreach ($fields as $key) {
|
|
$val = $_POST[$key] ?? null;
|
|
if ($val === null) continue;
|
|
$pdo->prepare("UPDATE config SET value = ? WHERE key = ?")->execute([$val, $key]);
|
|
}
|
|
$gen = $pdo->query("SELECT value FROM config WHERE key = 'caching_config_generation'")->fetchColumn();
|
|
$new_gen = intval($gen) + 1;
|
|
$pdo->prepare("UPDATE config SET value = ? WHERE key = 'caching_config_generation'")->execute([$new_gen]);
|
|
$pdo->commit();
|
|
$message = "Configuration saved. Config generation bumped to $new_gen. The caching service will reload automatically.";
|
|
} catch (Exception $e) {
|
|
$pdo->rollBack();
|
|
$error = 'Failed to save: ' . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$config_keys = [
|
|
'caching_root_npubs' => 'Root npubs (comma-separated npub... values)',
|
|
'caching_bootstrap_relays' => 'Bootstrap relays (comma-separated wss://... URLs)',
|
|
'caching_kinds' => 'Kinds to cache (comma-separated integers)',
|
|
'caching_admin_kinds' => 'Admin kinds (* for all, or comma-separated)',
|
|
'caching_live_enabled' => 'Live subscription enabled (true/false)',
|
|
'caching_backfill_enabled' => 'Backfill enabled (true/false)',
|
|
'caching_backfill_page_size' => 'Backfill page size (events per tick)',
|
|
'caching_backfill_tick_interval_ms' => 'Backfill tick interval (ms)',
|
|
'caching_follow_graph_refresh_seconds' => 'Follow graph refresh interval (seconds)',
|
|
'caching_relay_discovery_refresh_seconds' => 'Relay discovery refresh (seconds)',
|
|
'caching_max_followed_pubkeys' => 'Max followed pubkeys',
|
|
'caching_max_upstream_relays' => 'Max upstream relays',
|
|
'caching_max_relays_per_pubkey' => 'Max relays per pubkey',
|
|
'caching_query_timeout_ms' => 'Query timeout (ms)',
|
|
'caching_live_resubscribe_seconds' => 'Live resubscribe interval (seconds)',
|
|
];
|
|
|
|
$values = [];
|
|
foreach (array_keys($config_keys) as $key) {
|
|
$stmt = $pdo->prepare("SELECT value FROM config WHERE key = ?");
|
|
$stmt->execute([$key]);
|
|
$values[$key] = $stmt->fetchColumn() ?: '';
|
|
}
|
|
|
|
admin_header('config', 'C-Relay-PG Admin — Config');
|
|
?>
|
|
|
|
<div class="section">
|
|
<div class="section-header">CACHING CONFIGURATION</div>
|
|
|
|
<?php if ($message): ?>
|
|
<p class="status-complete" style="padding:10px;border:1px solid #4caf50;border-radius:5px;margin-bottom:16px">✓ <?= e($message) ?></p>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<p class="status-error" style="padding:10px;border:1px solid var(--accent-color);border-radius:5px;margin-bottom:16px">✗ <?= e($error) ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form class="config-form" method="post">
|
|
<?php foreach ($config_keys as $key => $label): ?>
|
|
<div class="row">
|
|
<div>
|
|
<label for="<?= e($key) ?>"><?= e($label) ?></label>
|
|
<div class="hint"><?= e($key) ?></div>
|
|
</div>
|
|
<div>
|
|
<input type="text" id="<?= e($key) ?>" name="<?= e($key) ?>" value="<?= e($values[$key]) ?>">
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<button type="submit">Save & Apply (bumps config generation)</button>
|
|
</form>
|
|
|
|
<p style="margin-top:16px;color:var(--muted-color);font-size:10px">
|
|
Saving bumps <code>caching_config_generation</code> so the caching service
|
|
detects the change and hot-reloads. No relay restart needed.
|
|
</p>
|
|
</div>
|
|
|
|
<?php admin_footer(); ?>
|