mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 21:02:21 +01:00
* perf(metadata): serve the metadata dumps and fixtures from SQLite files
The LaunchBox and Switch TitleDB stores sat in valkey, which keeps every
byte resident: about 300MB on an instance with both imported, against
roughly 1MB for an empty server. Every read is an exact-key lookup and
nothing writes between imports, so they now live in read-only SQLite
files under RESOURCES_BASE_PATH/metadata, where the OS page cache holds
only the pages lookups touch.
A build writes a temporary file and renames it over the previous one,
so readers see the old store or the new one and never a partial import.
That replaces the initial-import flag and the schema stamp: the store
revision is part of the file name. A failed import keeps serving the
previous file.
The startup fixture indexes (MAME, ScummVM, Sony serials, known BIOS)
no longer get copied into valkey on every boot. They build on first use
into a file under the cache path, named after a hash of the JSON.
Startup deletes the old valkey keys and any file of an older revision,
and queues a rebuild when a store had data, so an upgrade refills
LaunchBox and TitleDB on its own. nginx returns 404 for the metadata
folder, since /assets/romm/resources is otherwise served without auth.
Measured against the real dumps: LaunchBox builds in 22s into 263MB on
disk, TitleDB in 1.2s into 54MB, the fixtures in 0.2s into 8MB. A hit
costs 10-23us including decompression, a miss about 7us.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: code-review
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: simplify
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: review-polish
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: prose
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: prose (code-review fixes)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Keep the previous metadata store when a dump comes out empty
A LaunchBox or TitleDB build that writes no rows to its main table now
fails with EmptyDumpError instead of swapping an empty store over a
populated one.
Each store keeps one connection per process behind a lock instead of one
per thread. A build closes it once it swaps the file in, and any other
process closes its own on its next lookup, so a replaced file's disk
space is released instead of held by idle threads.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Address Greptile review: trim DumpStore comments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Restore valkey's own snapshot policy by default
The hourly default (48259b3a9, #3980) kept valkey from rewriting the
hundreds of MB of LaunchBox and TitleDB data it held. With those moved to
SQLite files, a snapshot holds only sessions, queues and query caches, so
an unset REDIS_SAVE_POLICY now leaves valkey's stock policy in place and
loses less on a crash. An empty value still disables snapshots.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
5.8 KiB
Plaintext
161 lines
5.8 KiB
Plaintext
# This template is used to generate the default.conf file for the nginx server,
|
|
# by using `envsubst` to replace the environment variables in the template with
|
|
# their actual values.
|
|
|
|
# Gunicorn upstream. Defined here (not in nginx.conf) so the port stays in sync
|
|
# with the ${DEV_PORT} gunicorn binds to.
|
|
upstream wsgi_server {
|
|
server 127.0.0.1:${DEV_PORT};
|
|
}
|
|
|
|
# Helper to get scheme regardless if we are behind a proxy or not
|
|
map $http_x_forwarded_proto $forwardscheme {
|
|
default $scheme;
|
|
https https;
|
|
}
|
|
|
|
# COEP and COOP headers for cross-origin isolation, which are set only for the
|
|
# EmulatorJS and js-dos player paths, to enable SharedArrayBuffer support, which
|
|
# is needed for multi-threaded cores. Not $uri: try_files rewrites it to
|
|
# /index.html before add_header runs, so the query string is matched explicitly.
|
|
# frontend/scripts/playerIsolationHeaders.ts restates these entries for the dev server.
|
|
map $request_uri $coep_header {
|
|
default "";
|
|
~^/rom/.*/(ejs|jsdos)(\?|$) "require-corp";
|
|
}
|
|
map $request_uri $coop_header {
|
|
default "";
|
|
~^/rom/.*/(ejs|jsdos)(\?|$) "same-origin";
|
|
}
|
|
|
|
# The EasyRPG web player fetches each file of a game from games/<rom id>-<user id>/
|
|
# beside itself. Built from the raw $request_uri, so names keep the client's encoding.
|
|
map $request_uri $easyrpg_backend_uri {
|
|
default "";
|
|
~^/assets/easyrpg/games/(?<rom_id>[0-9]+)-[0-9]+/(?<easyrpg_path>[^?]*) /api/roms/$rom_id/easyrpg/$easyrpg_path;
|
|
}
|
|
|
|
# Library resources under /assets/romm/resources/ are a mix. Covers (?ts=) and
|
|
# manuals (?v=) are versioned by a known cache-busting query, so they can be
|
|
# frozen; screenshots and RA badges reuse stable filenames (0.jpg, ...) and are
|
|
# overwritten on re-scrape, so they must revalidate. Freeze only when a
|
|
# recognized version param (ts or v) is present, not on any arbitrary query
|
|
# (e.g. ?download=1 must not pin a screenshot for a year).
|
|
map $args $resources_cache_control {
|
|
default "public, max-age=3600, must-revalidate";
|
|
"~(^|&)(ts|v)=" "public, max-age=31536000, immutable";
|
|
}
|
|
|
|
# Resources and library files are served sandboxed. PDFs are exempt so the
|
|
# browser's PDF viewer still opens them; an empty value makes add_header skip
|
|
# the header.
|
|
map $uri $resources_csp {
|
|
default "sandbox; default-src 'none'; img-src 'self'; media-src 'self'; style-src 'unsafe-inline'";
|
|
"~*\.pdf$" "";
|
|
}
|
|
|
|
server {
|
|
root /var/www/html;
|
|
listen ${ROMM_PORT};
|
|
${IPV6_LISTEN}
|
|
server_name localhost;
|
|
|
|
${NGINX_ACCESS_LOG}
|
|
|
|
proxy_set_header Host $http_host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $forwardscheme;
|
|
|
|
# Serve the .gz siblings the frontend build writes. Scoped to the build output:
|
|
# the internal /library/ and /cache/ locations must never match a ROM's own
|
|
# .gz sibling, and library resources have no precompressed form.
|
|
location / {
|
|
gzip_static on;
|
|
try_files $uri $uri/ /index.html;
|
|
proxy_redirect off;
|
|
add_header Cache-Control "no-cache";
|
|
add_header Access-Control-Allow-Origin *;
|
|
add_header Access-Control-Allow-Methods *;
|
|
add_header Access-Control-Allow-Headers *;
|
|
add_header Cross-Origin-Embedder-Policy $coep_header;
|
|
add_header Cross-Origin-Opener-Policy $coop_header;
|
|
}
|
|
|
|
# Freeze content-hashed frontend bundles (fingerprinted files under /assets)
|
|
location ~* "^/assets/[^/]+-[A-Za-z0-9_-]{8,}\.(js|mjs|css|map|woff2?|ttf|otf|eot|svg|png|jpe?g|gif|webp|avif|ico|json|wasm)$" {
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
gzip_static on;
|
|
try_files $uri $uri/ =404;
|
|
}
|
|
|
|
# Freeze library resources carrying cache-busting query
|
|
location /assets/romm/resources/ {
|
|
add_header Cache-Control $resources_cache_control;
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header Content-Security-Policy $resources_csp;
|
|
try_files $uri $uri/ =404;
|
|
}
|
|
|
|
# Metadata dumps the backend reads in place; they are not library resources.
|
|
# Case-insensitive, since the resources volume can be too.
|
|
location ~* ^/assets/romm/resources/metadata/ {
|
|
return 404;
|
|
}
|
|
|
|
location ^~ /assets/easyrpg/games/ {
|
|
if ($easyrpg_backend_uri = "") {
|
|
return 404;
|
|
}
|
|
proxy_pass http://wsgi_server$easyrpg_backend_uri;
|
|
}
|
|
|
|
# Everything else under /assets keeps a stable URL across image upgrades
|
|
location /assets {
|
|
add_header Cache-Control "public, max-age=3600, must-revalidate";
|
|
gzip_static on;
|
|
try_files $uri $uri/ =404;
|
|
}
|
|
|
|
# OpenAPI for swagger and redoc
|
|
location /openapi.json {
|
|
proxy_pass http://wsgi_server;
|
|
}
|
|
|
|
# Backend api calls
|
|
location /api {
|
|
proxy_pass http://wsgi_server;
|
|
proxy_request_buffering off;
|
|
proxy_buffering off;
|
|
proxy_read_timeout 300s;
|
|
}
|
|
location ~ ^/(ws|netplay) {
|
|
proxy_pass http://wsgi_server;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# Internally redirect download requests
|
|
# X-Accel-Redirect drops the backend's CSP and nosniff headers, so they are
|
|
# set here for files served inline (uploaded HTML manuals among them).
|
|
location /library/ {
|
|
internal;
|
|
alias "${ROMM_BASE_PATH}/library/";
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header Content-Security-Policy $resources_csp;
|
|
}
|
|
|
|
# Internally redirect cached zip file requests (Range-resumable downloads)
|
|
location /cache/ {
|
|
internal;
|
|
alias "${ROMM_CACHE_BASE_PATH}/";
|
|
}
|
|
|
|
# Internal decoding endpoint, used to decode base64 encoded data
|
|
location /decode {
|
|
internal;
|
|
js_content decode.decodeBase64;
|
|
}
|
|
}
|