faster poll
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
const DISCORD_ID = '298221448642953217';
|
const DISCORD_ID = '298221448642953217';
|
||||||
const SITE_TITLE = '0xA0.dev';
|
const SITE_TITLE = '0xA0.dev';
|
||||||
|
const REPO_URL = 'https://git.0xa0.dev';
|
||||||
|
|
||||||
define('DATA_DIR', getenv('DATA_DIR') ?: '/var/www/data');
|
define('DATA_DIR', getenv('DATA_DIR') ?: '/var/www/data');
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<div class="buttons88x31">
|
<div class="buttons88x31">
|
||||||
<?= render_buttons_88x31() ?>
|
<?= render_buttons_88x31() ?>
|
||||||
</div>
|
</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>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<section class="status-widget">
|
<section class="status-widget">
|
||||||
<h2>status</h2>
|
<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'; ?>
|
<?php include __DIR__ . '/status.php'; ?>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
+4
-13
@@ -2,7 +2,7 @@
|
|||||||
require_once __DIR__ . '/config.php';
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
$cacheFile = DATA_DIR . '/lanyard.json';
|
$cacheFile = DATA_DIR . '/lanyard.json';
|
||||||
$ttl = 15;
|
$ttl = 2;
|
||||||
|
|
||||||
if (!function_exists('lanyard_refresh')) {
|
if (!function_exists('lanyard_refresh')) {
|
||||||
function lanyard_refresh(string $cacheFile): void {
|
function lanyard_refresh(string $cacheFile): void {
|
||||||
@@ -21,12 +21,11 @@ if (!function_exists('lanyard_refresh')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$haveCache = is_file($cacheFile);
|
$isPoll = realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__;
|
||||||
$stale = !$haveCache || (time() - filemtime($cacheFile) > $ttl);
|
$stale = !is_file($cacheFile) || (time() - filemtime($cacheFile) > $ttl);
|
||||||
|
|
||||||
if ($stale && !$haveCache) {
|
if ($stale && ($isPoll || !is_file($cacheFile))) {
|
||||||
lanyard_refresh($cacheFile);
|
lanyard_refresh($cacheFile);
|
||||||
$stale = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode(@file_get_contents($cacheFile), true)['data'] ?? null;
|
$data = json_decode(@file_get_contents($cacheFile), true)['data'] ?? null;
|
||||||
@@ -83,11 +82,3 @@ $banner = $bannerHash
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</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