mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-19 11:25:56 +00:00
preview: compressed module build cache with a clear dialog; module sources without client files
- Build cache (build_cache.rs): the build folder of a module is unpacked for a build and packed into <module>.tar.zst afterwards (object files ~4-6x smaller), modification times kept so Ninja recompiles only what changed. A cache made for another core is dropped instead of unpacked; .ilk and .map files are not kept; total limit 2 GB, least recently built first. The build log moves next to the archive (build-cache/<module>.log). - "Build cache" in the Modules menu: size per module (packed, built when, for this core or not), remove one, remove all, remove downloaded sources. Builds now hold the server's busy guard, so the cache is never cleared under a running build. - Module sources: "Add from a link" downloads GitHub's archive of the commit instead of a full git clone, and game-client files (.mpq, .dbc, maps, textures, archives) are left out and listed in .coa_skipped_assets. mod-bg-battle-for-gilneas: 365 MB repository, 3.1 MB kept (was refused at the 300 MB limit). - Overlay: Helias's battleground modules (Gilneas, Twin Peaks, Slavery Valley) are Incompatible: they need the server's DBC files replaced (CoA ships its own) and a client patch. Checked: build_cache unit tests; examples/build_cache_ninja_check with real MSVC + CMake + Ninja: after pack/unpack nothing is recompiled, after one edit one file is; coa-core lib tests 865 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3987f1b2ff
commit
899b7c6617
12 files changed
+705
-5
No files matched your search
@@ -479,6 +479,22 @@ export interface AccountInfo {
|
||||
characters: number;
|
||||
}
|
||||
|
||||
export interface BuildCacheEntry {
|
||||
module: string;
|
||||
bytes: number;
|
||||
unpacked_bytes: number;
|
||||
last_used: number;
|
||||
current_core: boolean;
|
||||
packed: boolean;
|
||||
}
|
||||
|
||||
export interface BuildCacheSummary {
|
||||
modules: BuildCacheEntry[];
|
||||
total_bytes: number;
|
||||
sources_bytes: number;
|
||||
limit_bytes: number;
|
||||
}
|
||||
|
||||
export interface CopyReport {
|
||||
schemas: string[];
|
||||
accounts: number;
|
||||
@@ -818,6 +834,9 @@ export const api = {
|
||||
installNew: (dest: string, pkg?: string, gameData?: string, copyFrom?: string) =>
|
||||
invoke<ServerSummary & { preview_core_error: string | null; modules_off: string[]; copied: CopyReport | null }>("install_new", { dest, package: pkg ?? null, gameData: gameData ?? null, copyFrom: copyFrom ?? null }),
|
||||
isClassicServer: (path: string) => invoke<boolean>("is_classic_server", { path }),
|
||||
buildCacheSummary: (id: string) => invoke<BuildCacheSummary>("build_cache_summary", { id }),
|
||||
buildCacheClear: (id: string, module: string | null, sources: boolean) =>
|
||||
invoke<number>("build_cache_clear", { id, module, sources }),
|
||||
cancelInstall: () => invoke<void>("cancel_install"),
|
||||
createAccount: (id: string, username: string, password: string, administrator: boolean) =>
|
||||
invoke<void>("create_account", { id, username, password, administrator }),
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Loader2, Trash2, X } from "lucide-react";
|
||||
import { api, asUiError, type BuildCacheSummary } from "@/lib/api";
|
||||
import { formatBytes } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
/** What the module build cache takes, with removal of one module, all modules, or the downloaded sources. */
|
||||
export function BuildCacheDialog(props: { serverId: string; locale: string; onClose: () => void }) {
|
||||
const ru = props.locale === "ru";
|
||||
const [summary, setSummary] = useState<BuildCacheSummary | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(() => {
|
||||
void api
|
||||
.buildCacheSummary(props.serverId)
|
||||
.then(setSummary)
|
||||
.catch((e) => setError(asUiError(e).technical));
|
||||
}, [props.serverId]);
|
||||
useEffect(load, [load]);
|
||||
|
||||
async function clear(key: string, module: string | null, sources: boolean) {
|
||||
setBusy(key);
|
||||
setError(null);
|
||||
try {
|
||||
const freed = await api.buildCacheClear(props.serverId, module, sources);
|
||||
setMessage(ru ? `Освобождено ${formatBytes(freed)}` : `Freed ${formatBytes(freed)}`);
|
||||
load();
|
||||
} catch (e) {
|
||||
setError(asUiError(e).technical);
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
const when = (secs: number) =>
|
||||
secs > 0 ? new Date(secs * 1000).toLocaleDateString(ru ? "ru-RU" : undefined, { day: "numeric", month: "short" }) : "—";
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4" role="dialog" aria-modal aria-label={ru ? "Кэш сборок" : "Build cache"}>
|
||||
<Card className="w-full max-w-lg space-y-4 border-line bg-card p-5 shadow-2xl">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 className="text-base font-semibold text-ink">{ru ? "Кэш сборок" : "Build cache"}</h3>
|
||||
<p className="mt-1 text-xs text-muted">
|
||||
{ru
|
||||
? "Скомпилированные части модулей хранятся сжатыми и ускоряют повторную сборку. После обновления ядра старый кэш удаляется сам. Удаление ничего не ломает: следующая сборка модуля будет полной."
|
||||
: "Compiled parts of modules are kept compressed and speed up the next build. After a core update the old cache goes by itself. Removing it breaks nothing: the next build of a module is a full one."}
|
||||
</p>
|
||||
</div>
|
||||
<button onClick={props.onClose} className="text-muted hover:text-ink" aria-label={ru ? "Закрыть" : "Close"}>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{!summary && !error && <Loader2 className="h-4 w-4 animate-spin text-gold" />}
|
||||
|
||||
{summary && (
|
||||
<>
|
||||
<div className="divide-y divide-line rounded border border-line text-sm">
|
||||
{summary.modules.length === 0 && <p className="p-3 text-xs text-muted">{ru ? "Кэш пуст." : "The cache is empty."}</p>}
|
||||
{summary.modules.map((m) => (
|
||||
<div key={m.module} className="flex items-center gap-3 px-3 py-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate font-medium text-ink">{m.module}</p>
|
||||
<p className="text-[11px] text-muted">
|
||||
{m.packed
|
||||
? ru ? `сжато из ${formatBytes(m.unpacked_bytes)}` : `packed from ${formatBytes(m.unpacked_bytes)}`
|
||||
: ru ? "не сжато" : "not packed"}
|
||||
{" · "}
|
||||
{ru ? "сборка " : "built "}
|
||||
{when(m.last_used)}
|
||||
{!m.current_core && (ru ? " · для другого ядра" : " · for another core")}
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-xs tabular-nums text-muted">{formatBytes(m.bytes)}</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
disabled={busy !== null}
|
||||
onClick={() => void clear(m.module, m.module, false)}
|
||||
aria-label={ru ? `Удалить кэш ${m.module}` : `Remove the cache of ${m.module}`}
|
||||
className="h-7 w-7 p-0 text-muted hover:text-bad"
|
||||
>
|
||||
{busy === m.module ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Trash2 className="h-3.5 w-3.5" />}
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between text-xs text-muted">
|
||||
<span>
|
||||
{ru ? "Скачанные исходники модулей" : "Downloaded module sources"}: {formatBytes(summary.sources_bytes)}
|
||||
</span>
|
||||
<Button size="sm" variant="ghost" disabled={busy !== null || summary.sources_bytes === 0} onClick={() => void clear("sources", null, true)} className="h-7 text-xs">
|
||||
{busy === "sources" ? <Loader2 className="mr-1 h-3.5 w-3.5 animate-spin" /> : null}
|
||||
{ru ? "Удалить" : "Remove"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between border-t border-line pt-3">
|
||||
<span className="text-xs text-muted">
|
||||
{ru ? "Всего" : "Total"}: {formatBytes(summary.total_bytes)}
|
||||
{ru ? `, предел ${formatBytes(summary.limit_bytes)}` : `, limit ${formatBytes(summary.limit_bytes)}`}
|
||||
</span>
|
||||
<Button size="sm" variant="ghost" disabled={busy !== null || summary.modules.length === 0} onClick={() => void clear("all", null, false)} className="h-7 border border-line text-xs">
|
||||
{busy === "all" ? <Loader2 className="mr-1 h-3.5 w-3.5 animate-spin" /> : <Trash2 className="mr-1 h-3.5 w-3.5" />}
|
||||
{ru ? "Удалить весь кэш сборок" : "Remove the whole build cache"}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{message && <p className="text-xs text-ok" role="status">{message}</p>}
|
||||
{error && <p className="text-xs text-bad" role="alert">{error}</p>}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -57,6 +57,8 @@ import { useHuman, useI18n, useSchemaText, type Key } from "@/i18n";
|
||||
import { auctionWeightKey, canonicalModuleValue, moduleEnableKey, moduleField, retiredModuleKeys } from "@/lib/moduleSettings";
|
||||
import { AuctionTypes } from "@/screens/AuctionTypes";
|
||||
import { RaceAvailabilitySettings } from "@/screens/RaceAvailabilitySettings";
|
||||
import { BuildCacheDialog } from "@/screens/BuildCacheDialog";
|
||||
import { formatBytes } from "@/lib/utils";
|
||||
import type { UnsavedChangesGuard } from "@/lib/unsavedGuard";
|
||||
|
||||
/** The GitHub mark */
|
||||
@@ -639,6 +641,13 @@ export function ModulesPage({
|
||||
// "Add from a link" stays folded away until asked for; the menu holds the rarely used build tools.
|
||||
const [showUrlBar, setShowUrlBar] = useState(false);
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const [cacheOpen, setCacheOpen] = useState(false);
|
||||
const [cacheBytes, setCacheBytes] = useState<number | null>(null);
|
||||
useEffect(() => {
|
||||
if (menuOpen) {
|
||||
void api.buildCacheSummary(serverId).then((s) => setCacheBytes(s.total_bytes + s.sources_bytes)).catch(() => setCacheBytes(null));
|
||||
}
|
||||
}, [menuOpen, serverId]);
|
||||
const [analyzing, setAnalyzing] = useState(false);
|
||||
const [analysisError, setAnalysisError] = useState<string | null>(null);
|
||||
const [report, setReport] = useState<CompatibilityReport | null>(null);
|
||||
@@ -1234,6 +1243,17 @@ export function ModulesPage({
|
||||
{tab === "builds" && building && <Loader2 className="ml-auto h-3.5 w-3.5 animate-spin text-gold" />}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
role="menuitem"
|
||||
onClick={() => {
|
||||
setMenuOpen(false);
|
||||
setCacheOpen(true);
|
||||
}}
|
||||
className="flex w-full items-center gap-2 rounded px-2.5 py-1.5 text-left text-muted hover:bg-white/5 hover:text-ink"
|
||||
>
|
||||
<Database className="h-4 w-4" /> {locale === "ru" ? "Кэш сборок" : "Build cache"}
|
||||
{cacheBytes !== null && <span className="ml-auto text-xs tabular-nums">{formatBytes(cacheBytes)}</span>}
|
||||
</button>
|
||||
<button
|
||||
role="menuitem"
|
||||
disabled={actionInProgress === "export-diag"}
|
||||
@@ -1271,6 +1291,8 @@ export function ModulesPage({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cacheOpen && <BuildCacheDialog serverId={serverId} locale={locale} onClose={() => setCacheOpen(false)} />}
|
||||
|
||||
{/* Build tools: said only when something is missing */}
|
||||
{toolchain && activeTab !== "toolchain" && (() => {
|
||||
const missing = [
|
||||
|
||||
Reference in new issue
Block a user