Lighten library cache reports and heartbeat cleanup
This commit is contained in:
@@ -332,9 +332,17 @@ function transferProgress(value: unknown, status: LibraryCacheState): LibraryTra
|
||||
bytesPerSecond: progress.bytesPerSecond as number | null ?? null, etaSeconds: progress.etaSeconds as number | null ?? null };
|
||||
}
|
||||
|
||||
type LibraryCacheMetadata = Pick<GameLibraryVersion, 'state' | 'sizeBytes' | 'manifestSha256'>;
|
||||
const publishedCacheMetadata = new WeakMap<ReturnType<typeof database>, Map<string, LibraryCacheMetadata>>();
|
||||
|
||||
export function updateHostLibraryCaches(hostId: string, input: unknown, options: { snapshot?: boolean } = {}): void {
|
||||
if (!Array.isArray(input) || input.length > 2000) throw new Error('Invalid host library report.');
|
||||
const handle = database();
|
||||
// Published metadata is immutable. Keep caches local to the connection and
|
||||
// avoid retaining a publication from an outer transaction that may roll back.
|
||||
const versions = handle.inTransaction ? new Map<string, LibraryCacheMetadata>()
|
||||
: publishedCacheMetadata.get(handle) ?? new Map<string, LibraryCacheMetadata>();
|
||||
if (!handle.inTransaction) publishedCacheMetadata.set(handle, versions);
|
||||
const now = new Date().toISOString();
|
||||
handle.transaction(() => {
|
||||
const reported = new Set<string>();
|
||||
@@ -344,7 +352,10 @@ export function updateHostLibraryCaches(hostId: string, input: unknown, options:
|
||||
if (typeof id !== 'string') throw new Error('Invalid library version ID.');
|
||||
if (reported.has(id)) throw new Error('Duplicate version in host cache report.');
|
||||
reported.add(id);
|
||||
const version = getLibraryVersion(id); if (!version || version.state !== 'ready') continue;
|
||||
const version = versions.get(id) ?? handle.prepare(`SELECT state, size_bytes AS sizeBytes, manifest_sha256 AS manifestSha256
|
||||
FROM game_file_versions WHERE id=?`).get(id) as LibraryCacheMetadata | undefined;
|
||||
if (!version || version.state !== 'ready') continue;
|
||||
versions.set(id, version);
|
||||
let status = raw.status ?? raw.state;
|
||||
if (!['missing', 'downloading', 'verifying', 'ready', 'failed', 'outdated'].includes(status)) throw new Error('Invalid library cache state.');
|
||||
const checksum = typeof raw.manifestSha256 === 'string' ? raw.manifestSha256 : null;
|
||||
|
||||
Reference in New Issue
Block a user