perf: save only changed accounts, cache missing assets, lighter logging and backup

Ping on prod jumped to seconds because node's main thread was busy most
of every second.

- accounts.save(account, ...) names the changed accounts, which are
  written within a second; the rest are looked at a few at a time
  (10 ms a save for those in play, 5 ms for the others). One save under
  prod-like load: 289 ms before, 16 ms after.
- an asset the CDN does not have gets a cacheable 404 and is logged once
- the proxy's own connections no longer count against the web cap, which
  had node reset requests nginx had already let in
- a repeated client error is written once in ten minutes; the panel's
  log buffer trims in batches
- the daily backup uses sqlite's online backup off the main thread
This commit is contained in:
Burrowdev committed 2026-10-17 11:57:40 +03:00
1 parent edca7bf790
commit aa455f52d0
26 files changed
+334 -220

No files matched your search

+8 -8
View File
@@ -348,7 +348,7 @@ const gift = (account, body) => {
if (body.kind === "adopt") {
const ids = body.id === "all" ? defpacks.adoptAPetIds() : [body.id];
const given = ids.filter(id => adopt.give(account, id)).length;
accounts.save();
accounts.save(account);
return given ? {ok: `${name} has ${given} more on their Adopt-A-Pet checklist (it shows after their next login).`}
: {error: "No such Adopt-A-Pet, or they already have it."};
}
@@ -381,7 +381,7 @@ const act = (account, body) => {
// they cannot.
case "unlock":
account.locked = false;
accounts.save();
accounts.save(account);
return {ok: `${name} is unlocked.`};
// for a player who lost their phone and their recovery codes: their
// password alone signs them in again.
@@ -390,7 +390,7 @@ const act = (account, body) => {
return {error: `${name} does not use 2FA.`};
}
totp.turnOff(account);
accounts.save();
accounts.save(account);
return {ok: `2FA is off for ${name}.`};
case "rename": {
world.disconnect(account);
@@ -413,7 +413,7 @@ const act = (account, body) => {
return {error: "Pick a date and time in the past."};
}
account.lastSeen = when;
accounts.save();
accounts.save(account);
return {ok: `${name} was last seen ${new Date(when * 1000).toISOString().replace("T", " ").slice(0, 16)} UTC, as far as the game knows.`};
}
// the adventure level of the animal they are using.
@@ -431,7 +431,7 @@ const act = (account, body) => {
return {error: "Unknown badge."};
}
badges.set(account, body.badges);
accounts.save();
accounts.save(account);
world.checkNameTag(account);
return {ok: account.badges.length ? `${name} has: ${badges.of(account).map(badge => badge.label).join(", ")}.` : `${name} has no badges.`};
}
@@ -443,7 +443,7 @@ const act = (account, body) => {
return {error: "Not a Discord username."};
}
account.discord = discord;
accounts.save();
accounts.save(account);
return {ok: discord ? `Discord set to "${discord}".` : "Discord cleared."};
}
// their bio, which they otherwise write on the account page; empty
@@ -454,7 +454,7 @@ const act = (account, body) => {
return {error: `At most ${badges.MAX_BIO} characters on ${badges.MAX_BIO_LINES} lines.`};
}
account.bio = bio;
accounts.save();
accounts.save(account);
return {ok: bio ? "Bio set." : "Bio cleared."};
}
case "ban": {
@@ -496,7 +496,7 @@ const act = (account, body) => {
delete account.moderator;
modpanel.forget(account);
}
accounts.save();
accounts.save(account);
return {ok: body.on === true
? `${name} is a moderator.${totp.isOn(account) ? "" : " They have no 2FA yet and cannot sign in to the moderator panel until they turn it on."}`
: `${name} is no longer a moderator.`};