Perf & feedback upgrades to cache-asset-manifests

I want to start running this on a regular cron, and making the script faster (stop sending redundant queries) and clearer (# actually updated) is super useful for that!
This commit is contained in:
Emi Matchu 2021-01-20 09:49:05 -08:00
parent ccd4885aad
commit 6da2ddb453

View file

@ -17,7 +17,7 @@ const neopetsAssets = require("../src/server/neopets-assets");
async function cacheAssetManifests(db) { async function cacheAssetManifests(db) {
const [rows] = await db.execute( const [rows] = await db.execute(
`SELECT id, url FROM swf_assets ` + `SELECT id, url, manifest FROM swf_assets ` +
`WHERE manifest IS NULL OR manifest = "" AND id >= ? ` + `WHERE manifest IS NULL OR manifest = "" AND id >= ? ` +
`ORDER BY id`, `ORDER BY id`,
[argv.start || 0] [argv.start || 0]
@ -25,6 +25,7 @@ async function cacheAssetManifests(db) {
const numRowsTotal = rows.length; const numRowsTotal = rows.length;
let numRowsStarted = 0; let numRowsStarted = 0;
let numRowsUpdated = 0;
let numRowsDone = 0; let numRowsDone = 0;
async function cacheAssetManifest(row) { async function cacheAssetManifest(row) {
@ -38,6 +39,8 @@ async function cacheAssetManifests(db) {
// TODO: Someday the manifests will all exist, right? So we'll want to // TODO: Someday the manifests will all exist, right? So we'll want to
// reload all the missing ones at that time. // reload all the missing ones at that time.
manifest = manifest || ""; manifest = manifest || "";
let updated = false;
if (row.manifest !== manifest) {
if (argv.mode === "dump") { if (argv.mode === "dump") {
// Make it a JSON string, then escape the string for the query. // Make it a JSON string, then escape the string for the query.
// Hacky for sure! // Hacky for sure!
@ -59,6 +62,9 @@ async function cacheAssetManifests(db) {
); );
} }
} }
updated = true;
numRowsUpdated++;
}
numRowsDone++; numRowsDone++;
@ -66,7 +72,8 @@ async function cacheAssetManifests(db) {
// write to stderr, to not disrupt the dump // write to stderr, to not disrupt the dump
console.error( console.error(
`${percent}% ${numRowsDone}/${numRowsTotal} ` + `${percent}% ${numRowsDone}/${numRowsTotal} ` +
`(Exists? ${Boolean(manifest)}. Layer: ${row.id}, ${row.url}.)` `(Exists? ${Boolean(manifest)}. Updated? ${updated}. ` +
`Layer: ${row.id}, ${row.url}.)`
); );
} catch (e) { } catch (e) {
console.error(`Error loading layer ${row.id}, ${row.url}.`, e); console.error(`Error loading layer ${row.id}, ${row.url}.`, e);
@ -87,7 +94,7 @@ async function cacheAssetManifests(db) {
await pool.start(); await pool.start();
// write to stderr, to not disrupt the dump // write to stderr, to not disrupt the dump
console.error("Done!"); console.error(`Done! Updated ${numRowsUpdated} of ${numRowsDone} rows.`);
} }
async function main() { async function main() {