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

+12 -12
View File
@@ -79,7 +79,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
item.on.push(avatar.avInvId);
}
}
accounts.save();
accounts.save(account);
// ItemXtCommManager.itemsChangedListResponse, "3" = what is worn
// changed: [3, inUse, perUserAvId, username, colour, onCount,
// offCount, (invIdx, defId)..., offInvIdx...]
@@ -131,7 +131,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
}
const items = wornItems(account, avatar).map(item => item.inv);
account.outfits = [...account.outfits.filter(entry => entry !== existing), {name, items}];
accounts.save();
accounts.save(account);
tell(session, `Outfit ${name} saved (${items.length} items).`);
return;
}
@@ -152,7 +152,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
return;
}
account.outfits = account.outfits.filter(entry => entry.name !== name);
accounts.save();
accounts.save(account);
tell(session, `Outfit ${name} deleted.`);
return;
case "list":
@@ -194,7 +194,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
item.spots = item.spots || {};
item.spots[account.activeDen] = {cat: spot.cat || 1, x: spot.x, y: spot.y, flip: spot.flip};
}
accounts.save();
accounts.save(account);
dens.sendDenItems(session);
const room = session.room && session.room.denOwner === account ? session.room : null;
for (const occupant of room ? room.sessions : []) {
@@ -217,7 +217,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
}
const items = layoutOf(account);
account.denLayouts = [...account.denLayouts.filter(entry => entry !== existing), {name, den: activeDenDef(account), items}];
accounts.save();
accounts.save(account);
tell(session, `Den layout ${name} saved (${items.length} items).`);
return;
}
@@ -266,7 +266,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
}
const missing = applyLayout(session, undo.items, false);
account.denUndo = null;
accounts.save();
accounts.save(account);
tell(session, missing ? `Your den is back as it was, apart from ${missing} items that are no longer yours.` : "Your den is back as it was.");
return;
}
@@ -276,7 +276,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
return;
}
account.denLayouts = account.denLayouts.filter(entry => entry.name !== name);
accounts.save();
accounts.save(account);
tell(session, `Den layout ${name} deleted.`);
return;
case "list":
@@ -373,7 +373,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
const themes = require("../config.js").themes;
if (action === "random" && (choice === "on" || choice === "off")) {
account.randomTheme = choice === "on";
accounts.save();
accounts.save(account);
tell(session, account.randomTheme ? "The lands get a look picked at random each time you log in." : "The lands keep the look you choose.");
}
else if (action === "here" && session.room && !session.room.denOwner && (choice === "off" || Object.hasOwn(themes, choice))) {
@@ -383,7 +383,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
else {
account.roomThemes[session.room.base] = choice;
}
accounts.save();
accounts.save(account);
reloadRoom(session);
}
else if (action === "list") {
@@ -403,7 +403,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
}
const before = account.ecards.length;
account.ecards = account.ecards.filter(card => !card.read || card.gift);
accounts.save();
accounts.save(account);
tell(session, `${before - account.ecards.length} read Jam-A-Grams deleted. Open your mail again to see.`);
},
@@ -482,7 +482,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
}
else if (wanted.toLowerCase() === "off") {
delete account.denNames[account.activeDen];
accounts.save();
accounts.save(account);
tell(session, "This den has its usual name again.");
}
else if (isSilenced(account)) {
@@ -493,7 +493,7 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
}
else {
account.denNames[account.activeDen] = wanted;
accounts.save();
accounts.save(account);
tell(session, `This den is now called ${wanted}. It shows the next time someone walks in.`);
}
},