faster poll
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
const DISCORD_ID = '298221448642953217';
|
||||
const SITE_TITLE = '0xA0.dev';
|
||||
const REPO_URL = 'https://git.0xa0.dev';
|
||||
|
||||
define('DATA_DIR', getenv('DATA_DIR') ?: '/var/www/data');
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<div class="buttons88x31">
|
||||
<?= render_buttons_88x31() ?>
|
||||
</div>
|
||||
<small>© <?= date('Y') ?> · <a href="https://git.0xa0.dev">source</a> · build: <?= htmlspecialchars($build) ?></small>
|
||||
<small>© <?= date('Y') ?> · <a href="<?= htmlspecialchars(REPO_URL) ?>">build <?= htmlspecialchars($build) ?></a></small>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<section class="status-widget">
|
||||
<h2>status</h2>
|
||||
<div id="status" hx-get="/status.php" hx-trigger="every 10s" hx-ext="morph" hx-swap="morph:innerHTML">
|
||||
<div id="status" hx-get="/status.php" hx-trigger="every 3s" hx-ext="morph" hx-swap="morph:innerHTML">
|
||||
<?php include __DIR__ . '/status.php'; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
+4
-13
@@ -2,7 +2,7 @@
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
$cacheFile = DATA_DIR . '/lanyard.json';
|
||||
$ttl = 15;
|
||||
$ttl = 2;
|
||||
|
||||
if (!function_exists('lanyard_refresh')) {
|
||||
function lanyard_refresh(string $cacheFile): void {
|
||||
@@ -21,12 +21,11 @@ if (!function_exists('lanyard_refresh')) {
|
||||
}
|
||||
}
|
||||
|
||||
$haveCache = is_file($cacheFile);
|
||||
$stale = !$haveCache || (time() - filemtime($cacheFile) > $ttl);
|
||||
$isPoll = realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__;
|
||||
$stale = !is_file($cacheFile) || (time() - filemtime($cacheFile) > $ttl);
|
||||
|
||||
if ($stale && !$haveCache) {
|
||||
if ($stale && ($isPoll || !is_file($cacheFile))) {
|
||||
lanyard_refresh($cacheFile);
|
||||
$stale = false;
|
||||
}
|
||||
|
||||
$data = json_decode(@file_get_contents($cacheFile), true)['data'] ?? null;
|
||||
@@ -83,11 +82,3 @@ $banner = $bannerHash
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
if ($stale && realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__) {
|
||||
if (function_exists('fastcgi_finish_request')) {
|
||||
fastcgi_finish_request();
|
||||
}
|
||||
lanyard_refresh($cacheFile);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user