try to fix this spaghetti of a code

This commit is contained in:
Frederik Spirgi
2026-09-09 10:59:30 +02:00
parent 729de5dcc4
commit c43845356a
5 changed files with 23 additions and 9 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
const crypto = require('node:crypto');
const {EventEmitter} = require('node:events');
const {KeyedQueue, AppError, hash} = require('./core');
const {KeyedQueue, AppError, hash, canonical} = require('./core');
const engine = require('./engine');
function createLobbyService(repository, config) {
@@ -38,7 +38,7 @@ function createLobbyService(repository, config) {
return queue.run([...(membershipMutation ? ['membership'] : []), ...(username ? [`account:${username}`] : []),
...(message.lobbyId ? [`lobby:${message.lobbyId}`] : [])], async () => {
const id = `${username || 'system'}:${message.requestId}`;
const fingerprint = hash(JSON.stringify(message));
const fingerprint = hash(JSON.stringify(canonical(message)));
const prior = await repository.command(id);
if (prior) {
if (prior.fingerprint !== fingerprint) throw new AppError('IDEMPOTENCY_CONFLICT', 'Request ID was reused', 409);