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
+6
-6
@@ -267,7 +267,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
const offeredNames = toOwner.map(item => nameOf(item.type, item.entry));
|
||||
note(requester.account, owner.account, wantedName, offeredNames);
|
||||
note(owner.account, requester.account, offeredNames, wantedName);
|
||||
accounts.save();
|
||||
accounts.save(requester.account, owner.account);
|
||||
requester.sendXt("ti", -1, TRADE_PROGRESS, COMPLETED, 1, ...doneFields(wantedType, toRequester),
|
||||
offered.length, ...offered.flatMap(item => [doneType(item.type), item.entry.inv]));
|
||||
owner.sendXt("ti", -1, TRADE_PROGRESS, COMPLETED, toOwner.length, ...toOwner.flatMap(item => doneFields(item.type, item.entry)),
|
||||
@@ -308,7 +308,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
account.tradeList.push({type, inv});
|
||||
}
|
||||
}
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
sendTradeList(session, account);
|
||||
},
|
||||
|
||||
@@ -388,7 +388,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
return "too_many";
|
||||
}
|
||||
to.tradeOffers.push({id: to.nextInv++, fromId: from.id, at: Math.floor(Date.now() / 1000), wanted: want, offered: give});
|
||||
accounts.save();
|
||||
accounts.save(to);
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -406,7 +406,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
const given = from ? offer.offered.map(item => ({type: item.type, entry: find(from, item.type, item.inv)})) : [];
|
||||
if (accept && (!from || !wanted || given.some(item => !item.entry) || blocks.either(from, account)
|
||||
|| !fits(from, [offer.wanted], given) || !fits(account, given, [offer.wanted]))) {
|
||||
accounts.save();
|
||||
accounts.save(account);
|
||||
return "gone";
|
||||
}
|
||||
if (accept) {
|
||||
@@ -419,7 +419,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
// whoever is in the game sees their inventories change.
|
||||
[account, from].forEach(refresh);
|
||||
}
|
||||
accounts.save();
|
||||
accounts.save(account, from);
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -428,7 +428,7 @@ module.exports = ({findOnline, blocks}) => {
|
||||
const before = to ? to.tradeOffers.length : 0;
|
||||
if (to) {
|
||||
to.tradeOffers = to.tradeOffers.filter(offer => !(offer.id === Number(id) && offer.fromId === from.id));
|
||||
accounts.save();
|
||||
accounts.save(to);
|
||||
}
|
||||
return Boolean(to) && to.tradeOffers.length < before;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user