Read the expedition settings once per TCG state
The settings getter reread and remerged the SQL row on every access, seven times per getState. getState now builds the state inside a settings snapshot scoped to that synchronous build and released even on error, so an administrator's change still shows in the next state. An empty account now prepares 42 statements instead of 48. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2ba3e10005
commit
2f02c761a8
4 changed files with 48 additions and 0 deletions
|
|
@ -51,6 +51,31 @@ function goSolo(service, playerId, body, key) {
|
|||
return { ...departed, expedition: service.expeditions.expeditionView(group.id, playerId) };
|
||||
}
|
||||
|
||||
test("a state reads the expedition settings once, and the next state sees an administrator's change", () => {
|
||||
const { service, player, open } = expeditionService();
|
||||
const settingsQuery = "SELECT settings_json FROM expedition_settings WHERE id = 1";
|
||||
const prepare = service.db.prepare.bind(service.db);
|
||||
let reads = 0;
|
||||
service.db.prepare = (sql) => {
|
||||
if (sql === settingsQuery) reads += 1;
|
||||
return prepare(sql);
|
||||
};
|
||||
|
||||
assert.equal(service.getState(player.id).expeditions.enabled, false);
|
||||
assert.equal(reads, 1);
|
||||
open();
|
||||
reads = 0;
|
||||
assert.equal(service.getState(player.id).expeditions.enabled, true);
|
||||
assert.equal(reads, 1);
|
||||
// Hors d'une construction d'état, chaque accès relit la base, même après un état interrompu par une erreur.
|
||||
assert.throws(() => service.getState("missing-player"), (error) => error.code === "PLAYER_NOT_FOUND");
|
||||
assert.equal(service.expeditions.settingsSnapshot, null);
|
||||
reads = 0;
|
||||
void service.expeditions.settings;
|
||||
void service.expeditions.settings;
|
||||
assert.equal(reads, 2);
|
||||
});
|
||||
|
||||
test("expeditions stay closed until an administrator opens them", () => {
|
||||
const { service, player, open, rares } = expeditionService();
|
||||
const closed = service.expeditions.getExpeditions(player.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue