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

+9 -9
View File
@@ -149,7 +149,7 @@ const giveDenItem = (account, defId, version = 0) => {
}
const item = {inv: account.nextInv++, def: Number(defId), version: Number(version) || 0, spots: {}};
account.denItems.push(item);
accounts.save();
accounts.save(account);
return item;
};
@@ -167,7 +167,7 @@ const clearDen = (owner, findOnline) => {
for (const pet of petsInDen(owner)) {
delete pet.inDen;
}
accounts.save();
accounts.save(owner);
const ownerSession = findOnline(owner.username);
const room = ownerSession && ownerSession.room && ownerSession.room.denOwner === owner ? ownerSession.room : null;
for (const session of room ? room.sessions : []) {
@@ -231,7 +231,7 @@ const handlers = ({others, findOnline}) => {
account.currency[currency] -= purchase.cost;
achievements.currencyChanged(account, currency, -purchase.cost);
account.dens.push({inv: freeSlot(account, /^\d{1,3}$/.test(String(slot)) ? Number(slot) : NaN), def: purchase.defId});
accounts.save();
accounts.save(account);
session.sendXt("db", -1, 1, account.currency[currency], 0, purchase.currencyType, 0);
sendDenList(session);
};
@@ -259,7 +259,7 @@ const handlers = ({others, findOnline}) => {
masterpieces.claim(paintingId, frame);
const item = giveDenItem(account, masterpieces.DEN_ITEM, frame);
item.image = String(paintingId);
accounts.save();
accounts.save(account);
console.log(`[world] ${account.username} made masterpiece ${item.image}${masterpieces.itemApproved(item) ? "" : " (waiting for review in the admin panel)"}`);
session.sendXt("db", -1, 1, account.currency.diamonds || 0, 0, CURRENCY_DIAMONDS, item.inv);
sendDenItems(session);
@@ -289,7 +289,7 @@ const handlers = ({others, findOnline}) => {
achievements.currencyChanged(account, "gems", refund);
recycled.push(den.inv);
}
accounts.save();
accounts.save(account);
session.sendXt("dr", -1, recycled.length, account.currency.gems, ...recycled);
// the switcher empties the slot itself; the items that come back need
// the inventory's list.
@@ -418,7 +418,7 @@ const handlers = ({others, findOnline}) => {
}
applied.push(item.inv);
}
accounts.save();
accounts.save(account);
session.sendXt("dss", -1, ...applied);
if (inOwnDen(session)) {
for (const other of others(session)) {
@@ -452,7 +452,7 @@ const handlers = ({others, findOnline}) => {
account.denItems.splice(index, 1);
recycled.push(invIdx);
}
accounts.save();
accounts.save(account);
session.sendXt("dr", -1, recycled.length, account.currency.gems, ...recycled);
if (recycled.length) {
sendDenItems(session);
@@ -486,7 +486,7 @@ const handlers = ({others, findOnline}) => {
return;
}
account.activeDen = den.inv;
accounts.save();
accounts.save(account);
const avatar = activeAvatar(account);
session.sendXt("dc", -1, den.def, avatar.perUserAvId, avatar.petInvId);
// what is free and what is placed differs from den to den.
@@ -520,7 +520,7 @@ const handlers = ({others, findOnline}) => {
}
else if ([DEN_LOCKED, DEN_BUDDIES_ONLY, DEN_OPEN].includes(Number(value))) {
session.account.denPrivacy = Number(value);
accounts.save();
accounts.save(session.account);
}
},
};