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) {
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 >= ? ` +
`ORDER BY id`,
[argv.start || 0]
@ -25,6 +25,7 @@ async function cacheAssetManifests(db) {
const numRowsTotal = rows.length;
let numRowsStarted = 0;
let numRowsUpdated = 0;
let numRowsDone = 0;
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
// reload all the missing ones at that time.
manifest = manifest || "";
let updated = false;
if (row.manifest !== manifest) {
if (argv.mode === "dump") {
// Make it a JSON string, then escape the string for the query.
// Hacky for sure!
@ -59,6 +62,9 @@ async function cacheAssetManifests(db) {
);
}
}
updated = true;
numRowsUpdated++;
}
numRowsDone++;
@ -66,7 +72,8 @@ async function cacheAssetManifests(db) {
// write to stderr, to not disrupt the dump
console.error(
`${percent}% ${numRowsDone}/${numRowsTotal} ` +
`(Exists? ${Boolean(manifest)}. Layer: ${row.id}, ${row.url}.)`
`(Exists? ${Boolean(manifest)}. Updated? ${updated}. ` +
`Layer: ${row.id}, ${row.url}.)`
);
} catch (e) {
console.error(`Error loading layer ${row.id}, ${row.url}.`, e);
@ -87,7 +94,7 @@ async function cacheAssetManifests(db) {
await pool.start();
// write to stderr, to not disrupt the dump
console.error("Done!");
console.error(`Done! Updated ${numRowsUpdated} of ${numRowsDone} rows.`);
}
async function main() {