mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
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:
1 parent
edca7bf790
commit
aa455f52d0
26 files changed
+334
-220
No files matched your search
+17
-17
@@ -248,7 +248,7 @@ const act = (account, body, req, from, res) => {
|
||||
return {error: NAME_ERRORS[problem] || NAME_ERRORS.invalid_username};
|
||||
}
|
||||
delete account.nameRejected;
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
console.log(`[account] a rejected username was replaced by "${account.username}" from ${from.address}`);
|
||||
return {ok: "Saved."};
|
||||
}
|
||||
@@ -291,7 +291,7 @@ const act = (account, body, req, from, res) => {
|
||||
accounts.revokeTokens(account);
|
||||
world.moderation.actions.kick(account);
|
||||
}
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
console.log(`[account] "${account.username}" ${account.locked ? "locked" : "unlocked"} from ${from.address}`);
|
||||
return {ok: account.locked ? "Locked." : "Unlocked."};
|
||||
}
|
||||
@@ -300,7 +300,7 @@ const act = (account, body, req, from, res) => {
|
||||
return {error: "Unknown setting."};
|
||||
}
|
||||
account.features[body.feature] = body.on;
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: "Saved."};
|
||||
}
|
||||
// two-step sign-in (lib/totp.js). turning it on: the password again,
|
||||
@@ -314,17 +314,17 @@ const act = (account, body, req, from, res) => {
|
||||
return {error: "Wrong password."};
|
||||
}
|
||||
const setup = totp.begin(account);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: "Scan the code.", setup};
|
||||
}
|
||||
case "twoStepConfirm": {
|
||||
const recovery = totp.confirm(account, body.code);
|
||||
if (!recovery) {
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {error: "Wrong code."};
|
||||
}
|
||||
accounts.revokeTokens(account);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
console.log(`[account] "${account.username}" turned two-step sign-in on from ${from.address}`);
|
||||
return {ok: "2FA is on.", recovery};
|
||||
}
|
||||
@@ -337,18 +337,18 @@ const act = (account, body, req, from, res) => {
|
||||
return {error: "Wrong password."};
|
||||
}
|
||||
if (!totp.verify(account, String(body.code || ""))) {
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {error: "Wrong code."};
|
||||
}
|
||||
totp.turnOff(account);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
res.setHeader("Set-Cookie", cookieHeader("", 0, DEVICE_COOKIE));
|
||||
console.log(`[account] "${account.username}" turned two-step sign-in off from ${from.address}`);
|
||||
return {ok: "2FA is off."};
|
||||
}
|
||||
case "forgetDevices":
|
||||
totp.forgetDevices(account);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: "Trusted devices forgotten."};
|
||||
// their bio, for the Bio tab of their card in the game. empty takes it off.
|
||||
case "bio": {
|
||||
@@ -361,13 +361,13 @@ const act = (account, body, req, from, res) => {
|
||||
return {error: `At most ${badges.MAX_BIO} characters on ${badges.MAX_BIO_LINES} lines.`};
|
||||
}
|
||||
account.bio = bio;
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: bio ? "Saved." : "Removed."};
|
||||
}
|
||||
// whether their card in the game shows how long they have played.
|
||||
case "playtimePublic":
|
||||
account.playtimePublic = body.on === true;
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: account.playtimePublic ? "Others can see your playtime on your card." : "Your playtime is private."};
|
||||
// their Discord username, for their card in the game. empty takes it off.
|
||||
case "discord": {
|
||||
@@ -376,7 +376,7 @@ const act = (account, body, req, from, res) => {
|
||||
return {error: "Not a Discord username."};
|
||||
}
|
||||
account.discord = name;
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: name ? "Saved." : "Removed."};
|
||||
}
|
||||
// the player's own words about a buddy; only they see them.
|
||||
@@ -392,7 +392,7 @@ const act = (account, body, req, from, res) => {
|
||||
else {
|
||||
delete account.buddyNotes[key];
|
||||
}
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return {ok: "Saved."};
|
||||
}
|
||||
// blocking and unblocking, as the game's own buttons do it.
|
||||
@@ -422,7 +422,7 @@ const act = (account, body, req, from, res) => {
|
||||
case "signOutEverywhere":
|
||||
accounts.revokeTokens(account);
|
||||
totp.forgetDevices(account);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
world.moderation.actions.kick(account);
|
||||
signOutOthers(account, req);
|
||||
return {ok: "Signed out everywhere."};
|
||||
@@ -495,7 +495,7 @@ const handle = async (req, res, url, from, web) => {
|
||||
failuresByAddress.record(from.key);
|
||||
if (known) {
|
||||
accounts.recordLogin(known, "web", from.address, false);
|
||||
accounts.save();
|
||||
accounts.save(known);
|
||||
}
|
||||
reply(401, {error: "Wrong username or password."});
|
||||
return;
|
||||
@@ -511,7 +511,7 @@ const handle = async (req, res, url, from, web) => {
|
||||
if (!totp.verify(account, String(body.code))) {
|
||||
failuresByAddress.record(from.key);
|
||||
accounts.recordLogin(account, "web", from.address, false);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
reply(401, {error: "Wrong code.", twoStep: true, captchaPass: captcha.issuePass(account, from)});
|
||||
return;
|
||||
}
|
||||
@@ -520,7 +520,7 @@ const handle = async (req, res, url, from, web) => {
|
||||
}
|
||||
}
|
||||
accounts.recordLogin(account, "web", from.address);
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
signIn(res, account, cookies);
|
||||
reply(200, {ok: true});
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user