Fix controller stalls during large collection launches
This commit is contained in:
@@ -43,9 +43,14 @@ export function getLibraryFile(versionId: string, path: string) {
|
||||
FROM game_file_entries f JOIN game_file_versions v ON v.id=f.version_id WHERE f.version_id=? AND f.path=?`)
|
||||
.get(versionId, path) as (GameFileEntry & { state: GameLibraryVersion['state']; sourceHostId: string; storageLocation: string }) | undefined ?? null;
|
||||
}
|
||||
/** Launch selection needs only the ID; manifests can contain tens of thousands of files. */
|
||||
export function newestReadyLibraryId(game: string): string | null {
|
||||
const row = database().prepare("SELECT v.id FROM game_file_versions v JOIN game_file_libraries l ON l.id=v.library_id WHERE l.game=? AND v.state='ready' ORDER BY v.published_at DESC, v.created_at DESC, v.rowid DESC LIMIT 1").get(game) as { id: string } | undefined;
|
||||
return row?.id ?? null;
|
||||
}
|
||||
export function newestReadyLibrary(game: string): GameLibraryVersion | null {
|
||||
const row = database().prepare("SELECT v.*, l.game FROM game_file_versions v JOIN game_file_libraries l ON l.id=v.library_id WHERE l.game=? AND v.state='ready' ORDER BY v.published_at DESC, v.created_at DESC, v.rowid DESC LIMIT 1").get(game) as VersionRow | undefined;
|
||||
return row ? versionFromRow(row) : null;
|
||||
const id = newestReadyLibraryId(game);
|
||||
return id ? getLibraryVersion(id) : null;
|
||||
}
|
||||
/** Hosts follow the latest successful publication for each game, including legacy libraries. */
|
||||
export function latestPublishedLibraries() {
|
||||
@@ -79,13 +84,20 @@ export function getHostLibraryCache(hostId: string, versionId: string): HostLibr
|
||||
const row = database().prepare('SELECT * FROM host_library_caches WHERE host_id=? AND version_id=?').get(hostId, versionId) as CacheRow | undefined;
|
||||
return row ? cacheFromRow(row) : null;
|
||||
}
|
||||
export function requireReadyLibrary(hostId: string, versionId: string): GameLibraryVersion {
|
||||
const version = getLibraryVersion(versionId);
|
||||
/** Admission and dispatch recheck readiness without loading or parsing the file manifest. */
|
||||
export function assertReadyLibrary(hostId: string, versionId: string): void {
|
||||
const handle = database();
|
||||
const version = handle.prepare('SELECT state, manifest_sha256 FROM game_file_versions WHERE id=?')
|
||||
.get(versionId) as Pick<VersionRow, 'state' | 'manifest_sha256'> | undefined;
|
||||
if (!version || version.state !== 'ready' || libraryFilesRetired(versionId)) throw new Error('Select an available published game-file version.');
|
||||
if (database().prepare("SELECT 1 FROM ec_host_operations WHERE host_id=? AND kind='library.remove' AND json_extract(payload,'$.libraryVersionId')=? AND state IN ('pending','accepted','running','unknown')").get(hostId, versionId)) throw new Error('This host copy is being removed.');
|
||||
const cache = getHostLibraryCache(hostId, versionId);
|
||||
if (!cache || !['ready', 'outdated'].includes(cache.status) || cache.manifestSha256 !== version.manifestSha256) throw new Error('The selected host must finish downloading and verifying this game-file version.');
|
||||
return version;
|
||||
if (handle.prepare("SELECT 1 FROM ec_host_operations WHERE host_id=? AND kind='library.remove' AND json_extract(payload,'$.libraryVersionId')=? AND state IN ('pending','accepted','running','unknown')").get(hostId, versionId)) throw new Error('This host copy is being removed.');
|
||||
const cache = handle.prepare('SELECT status, manifest_sha256 FROM host_library_caches WHERE host_id=? AND version_id=?')
|
||||
.get(hostId, versionId) as Pick<CacheRow, 'status' | 'manifest_sha256'> | undefined;
|
||||
if (!cache || !['ready', 'outdated'].includes(cache.status) || cache.manifest_sha256 !== version.manifest_sha256) throw new Error('The selected host must finish downloading and verifying this game-file version.');
|
||||
}
|
||||
export function requireReadyLibrary(hostId: string, versionId: string): GameLibraryVersion {
|
||||
assertReadyLibrary(hostId, versionId);
|
||||
return getLibraryVersion(versionId)!;
|
||||
}
|
||||
|
||||
function textField(input: unknown, label: string, max: number, required = true): string {
|
||||
|
||||
Reference in New Issue
Block a user