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
@@ -154,7 +154,7 @@ module.exports = ({findOnline, blocks}) => {
// a localization string (StartupPopups.setupGiftPopup).
const message = clean(text).replace(/^(?=[\s+-]*\d)/, "Gift: ");
deliver(to, {from: HQ_NAME, hq: true, card: art.cards[0], stamp: 0, msg: message, gift: attached});
accounts.save();
accounts.save(to);
return null;
};
@@ -165,7 +165,7 @@ module.exports = ({findOnline, blocks}) => {
return false;
}
deliver(to, {from: HQ_NAME, hq: true, card: art.cards[0], stamp: 0, msg: clean(text).replace(/^(?=[\s+-]*\d)/, "Note: "), gift: null});
accounts.save();
accounts.save(to);
return true;
};
@@ -268,7 +268,7 @@ module.exports = ({findOnline, blocks}) => {
if (gift) {
achievements.add(account, achievements.VARS.giftsSent);
}
accounts.save();
accounts.save(account, to);
reply(SENT);
},
@@ -277,7 +277,7 @@ module.exports = ({findOnline, blocks}) => {
const card = session.account.ecards.find(candidate => candidate.id === Number(msgId));
if (card) {
card.read = true;
accounts.save();
accounts.save(session.account);
}
session.sendXt("er", -1, msgId, card ? 1 : 0);
},
@@ -288,7 +288,7 @@ module.exports = ({findOnline, blocks}) => {
const {account} = session;
const before = account.ecards.length;
account.ecards = account.ecards.filter(card => card.id !== Number(msgId));
accounts.save();
accounts.save(account);
session.sendXt("ed", -1, 1, before - account.ecards.length, ...(before === account.ecards.length ? [] : [msgId]));
},
@@ -314,7 +314,7 @@ module.exports = ({findOnline, blocks}) => {
if (accept === "1") {
giveGift(session, gift);
}
accounts.save();
accounts.save(session.account);
session.sendXt("eg", -1, msgId, 1);
},
@@ -324,7 +324,7 @@ module.exports = ({findOnline, blocks}) => {
const valid = [FROM_EVERYONE, FROM_BUDDIES, FROM_NOBODY].includes(value);
if (valid) {
session.account.ecardPrivacy = value;
accounts.save();
accounts.save(session.account);
}
session.sendXt("ei", -1, valid ? 1 : 0);
},