Keep native collection launches responsive
This commit is contained in:
@@ -109,10 +109,29 @@ function buildRecipe(game: ZombieGame, mapSlug: string, includeContent: boolean)
|
||||
configFile: configFileForGame(game), configSource, files };
|
||||
}
|
||||
|
||||
export function summarizeRecipe(recipe: LaunchRecipePlan): LaunchRecipeSummary {
|
||||
export function summarizeRecipe(recipe: LaunchRecipePlan, fingerprint = sha256Buffer(Buffer.from(JSON.stringify(recipe)))): LaunchRecipeSummary {
|
||||
const { format: _format, files, ...summary } = recipe;
|
||||
return { ...summary, files: files.map(({ content: _content, ...file }) => file),
|
||||
fingerprint: sha256Buffer(Buffer.from(JSON.stringify(recipe))) };
|
||||
fingerprint };
|
||||
}
|
||||
|
||||
/** Keep the small detail response beside the immutable attempted file bytes. */
|
||||
export function recipeStorage(recipe: LaunchRecipePlan): { recipe: string; recipeSummary: string } {
|
||||
const encoded = JSON.stringify(recipe);
|
||||
return { recipe: encoded, recipeSummary: JSON.stringify(summarizeRecipe(recipe, sha256Buffer(Buffer.from(encoded)))) };
|
||||
}
|
||||
|
||||
export function recipeSummaryForDeployment(id: string): { recipe: LaunchRecipeSummary; blueprintName: string | null } | null {
|
||||
const row = db().prepare('SELECT recipe_summary, blueprint_name FROM server_launch_recipes WHERE deployment_id = ?')
|
||||
.get(id) as { recipe_summary: string | null; blueprint_name: string | null } | undefined;
|
||||
if (!row) return null;
|
||||
if (row.recipe_summary !== null) return { recipe: JSON.parse(row.recipe_summary), blueprintName: row.blueprint_name };
|
||||
// Old snapshots remain readable. Populate on first access, without making
|
||||
// controller startup scan and decode every retained plugin in its history.
|
||||
const launch = recipeForDeployment(id)!;
|
||||
const summary = summarizeRecipe(launch.recipe);
|
||||
db().prepare('UPDATE server_launch_recipes SET recipe_summary = ? WHERE deployment_id = ?').run(JSON.stringify(summary), id);
|
||||
return { recipe: summary, blueprintName: row.blueprint_name };
|
||||
}
|
||||
|
||||
export function recipeForDeployment(id: string): { recipe: LaunchRecipePlan; blueprintName: string | null } | null {
|
||||
|
||||
Reference in New Issue
Block a user