From ba5f8d70bed6d629cbffbad4cd260c6511c6e52e Mon Sep 17 00:00:00 2001 From: James Lyne Date: Mon, 14 Dec 2020 15:53:03 +0000 Subject: [PATCH] Drop updates with a timestamp before the last update check. Reduce update logging. --- src/api.ts | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index fa886b7..2093489 100644 --- a/src/api.ts +++ b/src/api.ts @@ -15,6 +15,7 @@ import { DynmapWorld } from "@/dynmap"; import { Sanitizer } from "@esri/arcgis-html-sanitizer"; +import {useStore} from "@/store"; const sanitizer = new Sanitizer(); @@ -303,23 +304,40 @@ function buildUpdates(data: Array): DynmapUpdates { markerSets: new Map(), tiles: [] as DynmapTileUpdate[], chat: [], - } + }, + dropped = { + stale: 0, + noSet: 0, + noId: 0, + unknownType: 0, + unknownCType: 0, + incompleteTile: 0, + notImplemented: 0, + }, + lastUpdate = useStore().state.updateTimestamp; + + let accepted = 0; for(const entry of data) { switch(entry.type) { case 'component': { + if(lastUpdate && entry.timestamp < lastUpdate) { + dropped.stale++; + continue; + } + if(!entry.id) { - console.warn(`Ignoring component update without an ID`); + dropped.noId++; continue; } if(!entry.set) { - console.warn(`Ignoring component update without a marker set`); + dropped.noSet++; continue; } if(entry.ctype !== 'markers') { - console.warn(`Ignoring component with unknown ctype ${entry.ctype}`); + dropped.unknownCType++; continue; } @@ -338,7 +356,6 @@ function buildUpdates(data: Array): DynmapUpdates { removed: entry.msg.endsWith('deleted'), }; - if(entry.msg.startsWith("marker")) { update.payload = update.removed ? undefined : buildMarker(entry); markerSetUpdates!.markerUpdates.push(Object.freeze(update)); @@ -355,30 +372,42 @@ function buildUpdates(data: Array): DynmapUpdates { markerSetUpdates!.lineUpdates.push(Object.freeze(update)); } + accepted++; + break; } case 'chat': //TODO + dropped.notImplemented++; break; case 'tile': if(!entry.name || !entry.timestamp) { - console.warn(`Ignoring tile update without a name or timestamp`); - break; + dropped.incompleteTile++; + continue; + } + + if(lastUpdate && entry.timestamp < lastUpdate) { + dropped.stale++; + continue; } updates.tiles.push({ name: entry.name, timestamp: entry.timestamp, }); + + accepted++; break; default: - console.warn(`Ignoring unknown update type ${entry.type}`); + dropped.unknownType++; } } + console.debug(`Updates: ${accepted} accepted. Rejected: `, dropped); + return updates; }