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
@@ -299,7 +299,7 @@ const login = (session, msg) => {
// before the session is findable, so that nothing is sent ahead of the
// login reply.
achievements.refresh(account);
accounts.save();
accounts.save(account);
online.set(key, session);
console.log(`[world] ${account.username} logged in as sfs user ${session.id}`);
session.sendXtJson(-1, {_cmd: "login", status: "1", params: loginParams(session)});
@@ -461,7 +461,7 @@ const makeColour = (account, rgbs, asker = null) => {
}
if (entry.created) {
account.coloursMade = {day: today, count: made + 1};
accounts.save();
accounts.save(account);
}
for (const recipient of entry.created ? online.values() : asker ? [asker] : []) {
recipient.sendXt("xcc", -1, 1, entry.id, ...entry.rgbs);
@@ -497,7 +497,7 @@ const handlers = {
.filter(Boolean).slice(0, MAX_FILTER_WORDS);
session.account.filter = {level: [0, 1, 2].includes(Number(level)) ? Number(level) : 0, mode: Number(mode) === 1 ? 1 : 0,
words: [...new Set(own)].join(","), chosen: true};
accounts.save();
accounts.save(session.account);
sendFilter(session);
},
@@ -769,7 +769,7 @@ const handlers = {
vars[id] = 0;
}
const earned = achievements.award(account, id);
accounts.save();
accounts.save(account);
achievements.sendVar(session, id, earned);
},
@@ -818,7 +818,7 @@ const handlers = {
const ok = Boolean(thing) && TYPED_NAME.test(wanted) && !moderation.isSilenced(account);
if (ok) {
thing.name = wanted;
accounts.save();
accounts.save(account);
if (kind === "a" && thing === activeAvatar(account)) {
sendAvatarData(session, session, thing.perUserAvId);
}
@@ -1004,7 +1004,7 @@ const leaveWorld = session => {
countPlaytime(session);
stats.session(session.account, (Date.now() - session.playStarted) / 1000);
accounts.release(session.account);
accounts.save();
accounts.save(session.account);
buddies.announce(session.account);
}
};
@@ -1055,7 +1055,7 @@ const setTheme = (account, theme) => {
return false;
}
account.theme = theme;
accounts.save();
accounts.save(account);
const session = findOnline(account.username);
if (session) {
reloadRoom(session);
@@ -1163,7 +1163,7 @@ const setHideBlocked = (session, hide) => {
}
account.hideBlocked = hide;
account.userVars[USER_VAR_HIDE_BLOCKED] = hide ? 1 : 0;
accounts.save();
accounts.save(account);
if (!hide) {
for (const other of blocked) {
sendAvatarCreate(session, other);
@@ -1420,7 +1420,7 @@ module.exports = {
return false;
}
account.blocked = block ? [...account.blocked, key] : account.blocked.filter(name => name !== key);
accounts.save();
accounts.save(account);
const session = findOnline(account.username);
if (session) {
(block ? onBlocked : onUnblocked)(session, target);
@@ -1439,7 +1439,7 @@ module.exports = {
return;
}
account.nameBarData &= ~0xFF00;
accounts.save();
accounts.save(account);
const session = findOnline(account.username);
if (session && session.room) {
// AvatarXtCommManager "an": [sfsUserId, nameBarData]
@@ -1455,7 +1455,7 @@ module.exports = {
const avatar = activeAvatar(account);
avatar.questLevel = level;
avatar.questXp = adventureModule.levelXp(level);
accounts.save();
accounts.save(account);
const session = findOnline(account.username);
if (session && session.room) {
for (const viewer of session.room.sessions) {
@@ -1542,7 +1542,7 @@ module.exports = {
dens.sendDenState(visitor, room, false);
}
}
accounts.save();
accounts.save(...changed, maker);
return true;
},