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
@@ -105,7 +105,7 @@ module.exports = ({findOnline, onBlocked, onUnblocked, partyTimeLeft}) => {
else if (!account.buddies.includes(key(target))) {
if (!target.buddyRequests.includes(key(account))) {
target.buddyRequests.push(key(account));
accounts.save();
accounts.save(account, target);
}
if (targetSession) {
targetSession.sendXt("ba", -1, REQUEST_INCOMING, account.username, USERNAME_SHOWN);
@@ -122,7 +122,7 @@ module.exports = ({findOnline, onBlocked, onUnblocked, partyTimeLeft}) => {
return;
}
account.buddyRequests = account.buddyRequests.filter(name => name !== key(requester));
accounts.save();
accounts.save(account);
const requesterSession = findOnline(requester.username);
if (accept !== "1" || account.buddies.includes(key(requester))
|| account.buddies.length >= MAX_BUDDIES || requester.buddies.length >= MAX_BUDDIES) {
@@ -135,7 +135,7 @@ module.exports = ({findOnline, onBlocked, onUnblocked, partyTimeLeft}) => {
requester.buddies.push(key(account));
achievements.add(account, achievements.VARS.buddiesAdded);
achievements.add(requester, achievements.VARS.buddiesAdded);
accounts.save();
accounts.save(account, requester);
sendStatus(session, requester, STATUS_UPDATE);
if (requesterSession) {
sendStatus(requesterSession, account, STATUS_ACCEPTED_YOUR_REQUEST);
@@ -149,7 +149,7 @@ module.exports = ({findOnline, onBlocked, onUnblocked, partyTimeLeft}) => {
if (other) {
account.buddies = account.buddies.filter(name => name !== key(other));
other.buddies = other.buddies.filter(name => name !== key(account));
accounts.save();
accounts.save(account, other);
const otherSession = findOnline(other.username);
if (otherSession) {
otherSession.sendXt("bd", -1, account.username);
@@ -165,7 +165,7 @@ module.exports = ({findOnline, onBlocked, onUnblocked, partyTimeLeft}) => {
const added = other && other !== account && !account.blocked.includes(key(other)) && account.blocked.length < MAX_BLOCKED;
if (added) {
account.blocked.push(key(other));
accounts.save();
accounts.save(account);
}
session.sendXt("bb", -1, username, other && other !== account && account.blocked.includes(key(other)) ? 1 : 0);
if (added) {
@@ -178,7 +178,7 @@ module.exports = ({findOnline, onBlocked, onUnblocked, partyTimeLeft}) => {
const other = accounts.byName(username);
const removed = other && account.blocked.includes(key(other));
account.blocked = account.blocked.filter(name => name !== String(username).toLowerCase());
accounts.save();
accounts.save(account);
session.sendXt("bu", -1, username, 1);
if (removed) {
onUnblocked(session, other);