mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-05 20:31:54 +00:00
Update dashboard lock dedupe to prefer latest dTag event
This commit is contained in:
1 parent
2dc2901693
commit
1c0a10dcab
1 file changed
+14
-3
+14
-3
@@ -242,7 +242,7 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// State
|
// State
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
/** @type {Map<string, object>} eventId -> parsed lock */
|
/** @type {Map<string, object>} dTag -> latest parsed lock */
|
||||||
const lockStore = new Map();
|
const lockStore = new Map();
|
||||||
/** @type {WebSocket[]} */
|
/** @type {WebSocket[]} */
|
||||||
const sockets = [];
|
const sockets = [];
|
||||||
@@ -352,6 +352,16 @@
|
|||||||
return lock.expiresAt != null && lock.expiresAt <= nowUnix();
|
return lock.expiresAt != null && lock.expiresAt <= nowUnix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldReplaceLock(existingLock, incomingLock) {
|
||||||
|
if (!existingLock) return true;
|
||||||
|
if (incomingLock.createdAt !== existingLock.createdAt) {
|
||||||
|
return incomingLock.createdAt > existingLock.createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deterministic tie-break: prefer lexicographically higher event id.
|
||||||
|
return (incomingLock.eventId || '') > (existingLock.eventId || '');
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// Platform styling
|
// Platform styling
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -592,9 +602,10 @@
|
|||||||
const event = data[2];
|
const event = data[2];
|
||||||
const lock = parseLockEvent(event);
|
const lock = parseLockEvent(event);
|
||||||
|
|
||||||
// De-duplicate: keep the event with earliest created_at per d-tag
|
// De-duplicate by dTag: keep one lock per d-tag, preferring the
|
||||||
|
// most recent created_at; if equal, replace deterministically by event id.
|
||||||
const existing = lockStore.get(lock.dTag);
|
const existing = lockStore.get(lock.dTag);
|
||||||
if (!existing || existing.createdAt > lock.createdAt) {
|
if (shouldReplaceLock(existing, lock)) {
|
||||||
lockStore.set(lock.dTag, lock);
|
lockStore.set(lock.dTag, lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user