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

+7 -7
View File
@@ -271,7 +271,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
}
account.currency.gems -= CARNIVAL_COST;
achievements.currencyChanged(account, "gems", -CARNIVAL_COST);
accounts.save();
accounts.save(account);
session.sendXt("cu", -1, CURRENCY_GEMS, account.currency.gems, 0);
game.serial2 = serial();
reply("pg", "1", hideSerial(game.serial2));
@@ -288,7 +288,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
if (tickets > 0) {
account.currency.tickets = (account.currency.tickets || 0) + tickets;
achievements.currencyChanged(account, "tickets", tickets);
accounts.save();
accounts.save(account);
session.sendXt("cu", -1, CURRENCY_TICKETS, account.currency.tickets, 0);
}
reply("gr", tickets);
@@ -315,7 +315,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
}
account.currency.gems -= CLAW_COST;
achievements.currencyChanged(account, "gems", -CLAW_COST);
accounts.save();
accounts.save(account);
session.sendXt("cu", -1, CURRENCY_GEMS, account.currency.gems, 0);
const prizes = clawPrizes(game.def);
const won = prizes.length > 0 && Math.random() < CLAW_WIN_CHANCE;
@@ -343,7 +343,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
gd(session, game, [keep]) {
if (keep === "1" && session.gamePrize) {
sendClothingAdded(session, addClothing(session.account, session.gamePrize.def, session.gamePrize.color));
accounts.save();
accounts.save(session.account);
}
session.gamePrize = null;
},
@@ -401,7 +401,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
}
account.currency.gems -= INVASION_COST;
achievements.currencyChanged(account, "gems", -INVASION_COST);
accounts.save();
accounts.save(account);
session.sendXt("cu", -1, CURRENCY_GEMS, account.currency.gems, 0);
const prizes = invasionPrizes();
session.prizeSerial = serial();
@@ -528,7 +528,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
if (valid) {
account.currency.gems = (account.currency.gems || 0) + amount;
achievements.currencyChanged(account, "gems", amount);
accounts.save();
accounts.save(account);
}
session.gemSerial = serial();
session.sendXt("mg", -1, session.gemSerial, 0);
@@ -547,7 +547,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
if (valid && (pet.mastery || 0) < MASTERY_FULL) {
pet.mastery = Math.min(MASTERY_FULL, (pet.mastery || 0) + amount);
nowFull = pet.mastery === MASTERY_FULL;
accounts.save();
accounts.save(account);
}
session.masterySerial = serial();
session.sendXt("ma", -1, session.masterySerial, nowFull ? 1 : 0);