perf: precompress heavy assets and self-heal missing gamedata originals (gzip_static)
This commit is contained in:
1 parent
d57424a9ee
commit
24d6cf7047
1 file changed
+20
@@ -2000,6 +2000,7 @@ update_client() {
|
||||
fi
|
||||
mkdir -p "$NITRO_CLIENT/dist/custom-themes"
|
||||
[ ! -f "$NITRO_CLIENT/dist/custom-themes/index.json" ] && echo '{"themes":[]}' > "$NITRO_CLIENT/dist/custom-themes/index.json"
|
||||
precompress_assets
|
||||
fix_perms
|
||||
return 0
|
||||
}
|
||||
@@ -3507,6 +3508,24 @@ http_status() {
|
||||
if [ -n "$code" ]; then echo "$code"; else echo 000; fi
|
||||
}
|
||||
|
||||
# Re-generate .gz sidecars for the heavy static assets so nginx `gzip_static`
|
||||
# serves them instantly (no per-request compression). Also restores any loose
|
||||
# original that was left behind as only the .gz sidecar — a state that would
|
||||
# otherwise make the origin 404 on those files.
|
||||
precompress_assets() {
|
||||
local root f base
|
||||
for root in "$(dirname "${GAMEDATA_CONF_DIR:-/var/www/Gamedata/config}")" "${NITRO_CLIENT:-/var/www/Octane}/dist"; do
|
||||
[ -d "$root" ] || continue
|
||||
while IFS= read -r f; do
|
||||
base="${f%.gz}"
|
||||
[ -f "$base" ] || { gunzip -k "$f" && warn "Restored missing original: %s" "$base"; }
|
||||
done < <(find "$root" -name "*.gz" -type f 2>/dev/null)
|
||||
find "$root" -type f \( -name "*.js" -o -name "*.css" -o -name "*.wasm" -o -name "*.json" -o -name "*.jsonc" \) -size +20k -print0 2>/dev/null \
|
||||
| while IFS= read -r -d '' f; do gzip -k -f -6 "$f"; done
|
||||
done
|
||||
ok "$(_t "Assets compressed for fast serving")"
|
||||
}
|
||||
|
||||
# TCP reachability probe for the websocket endpoint (curl cannot talk `wss://`).
|
||||
check_socket() {
|
||||
local url="$1" hostport host port
|
||||
@@ -3616,6 +3635,7 @@ cmd_fixlinks() {
|
||||
fi
|
||||
command -v redis-cli &>/dev/null && redis-cli FLUSHALL 2>/dev/null && ok "Redis flushed" || true
|
||||
fix_perms
|
||||
precompress_assets
|
||||
info "$(_t "Done — links fixed. Test the client now.")"
|
||||
release_lock
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user