faster poll
This commit is contained in:
+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