fix(ugc): store meshes compressed, serve LXFML from the database, log client downloads

Each model took about 18 MB (the .nif uncompressed beside its .gz, the
unbaked .nif for the dashboard), so the 2 GB cap held about 110 models and
the server kept evicting and remaking them while clients got 408s. Only the
.gz files are stored now (the dashboard's copies are inflated when asked
for), and the previous version keeps only its icon, stats and .nif.gz.

The LXFML needs no making: its downloads come from the ugc row (kept in
memory for the last few), so they're never waited for or evicted. Every
client download is logged with its answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-27 13:52:38 -05:00
parent 1a2758feab
commit 30da6575e3
6 changed files with 75 additions and 17 deletions

View File

@@ -5,17 +5,19 @@
#include <fstream>
#include <random>
#include "ZCompression.h"
namespace {
constexpr std::array KNOWN_FILES = {
"model.nif", "model.nif.gz", "model.nif.checksum",
"model.lxfml.gz", "model.lxfml.checksum",
"icon.dds.gz", "icon.dds.checksum", "icon.png",
"model.noao.nif", "stats.json", "combo.json",
"previous.icon.png", "previous.model.nif", "previous.model.noao.nif", "previous.stats.json",
"model.noao.nif", "model.noao.nif.gz", "stats.json", "combo.json",
"previous.icon.png", "previous.model.nif.gz", "previous.stats.json",
};
// What of the files made before is kept when an item is made again, for comparing (as previous.<name>)
constexpr std::array KEPT_FILES = { "icon.png", "model.nif", "model.noao.nif", "stats.json" };
constexpr std::array KEPT_FILES = { "icon.png", "model.nif.gz", "stats.json" };
const char* KindFolder(UgcStorage::Kind kind) {
return kind == UgcStorage::Kind::MODEL ? "models" : "modular";
@@ -180,3 +182,17 @@ std::vector<UgcStorage::Entry> UgcStorage::Evict(uint64_t maxBytes) const {
}
return removed;
}
std::optional<std::string> UgcStorage::ReadNif(Kind kind, LWOOBJID id, const std::string& name) const {
const auto read = [](const std::filesystem::path& path) -> std::optional<std::string> {
std::ifstream in(path, std::ios::binary);
if (!in) return std::nullopt;
return std::string(std::istreambuf_iterator<char>(in), {});
};
if (const auto packed = File(kind, id, name + ".gz")) {
const auto data = read(*packed);
return data ? ZCompression::Gunzip(*data) : std::nullopt;
}
if (const auto plain = File(kind, id, name)) return read(*plain);
return std::nullopt;
}