Fix dedupe for frontend raw packet delivery

This commit is contained in:
Jack Kingsman
2026-02-16 20:46:43 -08:00
parent 56fde32970
commit 0e25bd2281
12 changed files with 188 additions and 20 deletions
+31
View File
@@ -0,0 +1,31 @@
import type { RawPacket } from '../types';
/**
* Distinguish real-time RF observations from storage identity.
* observation_id is emitted per WS event; id is the DB row identity fallback.
*/
export function getRawPacketObservationKey(
packet: Pick<RawPacket, 'id' | 'observation_id'>
): string {
if (packet.observation_id !== undefined && packet.observation_id !== null) {
return `obs-${packet.observation_id}`;
}
return `db-${packet.id}`;
}
export function appendRawPacketUnique(
prev: RawPacket[],
packet: RawPacket,
maxPackets: number
): RawPacket[] {
const packetKey = getRawPacketObservationKey(packet);
if (prev.some((p) => getRawPacketObservationKey(p) === packetKey)) {
return prev;
}
const updated = [...prev, packet];
if (updated.length > maxPackets) {
return updated.slice(-maxPackets);
}
return updated;
}