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

+6 -6
View File
@@ -100,7 +100,7 @@ module.exports = ({others, findOnline, petFields}) => {
giveCharacter(pet);
account.pets.push(pet);
achievements.set(account, achievements.VARS.pets, Math.max(Number(account.userVars[achievements.VARS.pets]) || 0, account.pets.length));
accounts.save();
accounts.save(account);
session.sendXt("pc", -1, 1, account.currency.gems || 0, 0, pet.inv, ...petFields(pet), 0);
};
@@ -147,7 +147,7 @@ module.exports = ({others, findOnline, petFields}) => {
return;
}
activeAvatar(account).petInvId = pet ? pet.inv : 0;
accounts.save();
accounts.save(account);
const messageRoom = session.room ? session.room.id : -1;
session.sendXt("ps", messageRoom, 1, session.id, pet ? pet.inv : 0);
if (session.pos) {
@@ -171,7 +171,7 @@ module.exports = ({others, findOnline, petFields}) => {
avatar.petInvId = 0;
}
}
accounts.save();
accounts.save(account);
session.sendXt("pd", -1, 1, pet.inv);
},
@@ -187,7 +187,7 @@ module.exports = ({others, findOnline, petFields}) => {
return;
}
pet.uBits = ((pet.uBits & ~MASTERY_BITS) | (item << 8)) >>> 0;
accounts.save();
accounts.save(account);
session.sendXt("pm", -1, 1, pet.inv, pet.lBits, pet.uBits, pet.eBits);
if (pet.inv === activeAvatar(account).petInvId && session.pos) {
for (const other of others(session)) {
@@ -207,7 +207,7 @@ module.exports = ({others, findOnline, petFields}) => {
return;
}
pet.name = `${name1}|${name2}`;
accounts.save();
accounts.save(account);
session.sendXt("pn", -1, 1, pet.inv, pet.name);
},
@@ -224,7 +224,7 @@ module.exports = ({others, findOnline, petFields}) => {
return;
}
pet.uBits = ((pet.uBits & 0xFFF) | (parts[0] << 12) | (parts[1] << 16) | (parts[2] << 20)) >>> 0;
accounts.save();
accounts.save(account);
session.sendXt("pi", -1, 1, account.currency.gems || 0, pet.inv, pet.lBits, pet.uBits, pet.eBits);
if (session.pos) {
for (const other of others(session)) {