Drop updates with a timestamp before the last update check. Reduce update logging.
This commit is contained in:
parent
1128a9b0ba
commit
ba5f8d70be
45
src/api.ts
45
src/api.ts
@ -15,6 +15,7 @@ import {
|
|||||||
DynmapWorld
|
DynmapWorld
|
||||||
} from "@/dynmap";
|
} from "@/dynmap";
|
||||||
import { Sanitizer } from "@esri/arcgis-html-sanitizer";
|
import { Sanitizer } from "@esri/arcgis-html-sanitizer";
|
||||||
|
import {useStore} from "@/store";
|
||||||
|
|
||||||
const sanitizer = new Sanitizer();
|
const sanitizer = new Sanitizer();
|
||||||
|
|
||||||
@ -303,23 +304,40 @@ function buildUpdates(data: Array<any>): DynmapUpdates {
|
|||||||
markerSets: new Map<string, DynmapMarkerSetUpdates>(),
|
markerSets: new Map<string, DynmapMarkerSetUpdates>(),
|
||||||
tiles: [] as DynmapTileUpdate[],
|
tiles: [] as DynmapTileUpdate[],
|
||||||
chat: [],
|
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) {
|
for(const entry of data) {
|
||||||
switch(entry.type) {
|
switch(entry.type) {
|
||||||
case 'component': {
|
case 'component': {
|
||||||
|
if(lastUpdate && entry.timestamp < lastUpdate) {
|
||||||
|
dropped.stale++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(!entry.id) {
|
if(!entry.id) {
|
||||||
console.warn(`Ignoring component update without an ID`);
|
dropped.noId++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!entry.set) {
|
if(!entry.set) {
|
||||||
console.warn(`Ignoring component update without a marker set`);
|
dropped.noSet++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entry.ctype !== 'markers') {
|
if(entry.ctype !== 'markers') {
|
||||||
console.warn(`Ignoring component with unknown ctype ${entry.ctype}`);
|
dropped.unknownCType++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +356,6 @@ function buildUpdates(data: Array<any>): DynmapUpdates {
|
|||||||
removed: entry.msg.endsWith('deleted'),
|
removed: entry.msg.endsWith('deleted'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if(entry.msg.startsWith("marker")) {
|
if(entry.msg.startsWith("marker")) {
|
||||||
update.payload = update.removed ? undefined : buildMarker(entry);
|
update.payload = update.removed ? undefined : buildMarker(entry);
|
||||||
markerSetUpdates!.markerUpdates.push(Object.freeze(update));
|
markerSetUpdates!.markerUpdates.push(Object.freeze(update));
|
||||||
@ -355,30 +372,42 @@ function buildUpdates(data: Array<any>): DynmapUpdates {
|
|||||||
markerSetUpdates!.lineUpdates.push(Object.freeze(update));
|
markerSetUpdates!.lineUpdates.push(Object.freeze(update));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accepted++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'chat':
|
case 'chat':
|
||||||
//TODO
|
//TODO
|
||||||
|
dropped.notImplemented++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'tile':
|
case 'tile':
|
||||||
if(!entry.name || !entry.timestamp) {
|
if(!entry.name || !entry.timestamp) {
|
||||||
console.warn(`Ignoring tile update without a name or timestamp`);
|
dropped.incompleteTile++;
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lastUpdate && entry.timestamp < lastUpdate) {
|
||||||
|
dropped.stale++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
updates.tiles.push({
|
updates.tiles.push({
|
||||||
name: entry.name,
|
name: entry.name,
|
||||||
timestamp: entry.timestamp,
|
timestamp: entry.timestamp,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
accepted++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn(`Ignoring unknown update type ${entry.type}`);
|
dropped.unknownType++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.debug(`Updates: ${accepted} accepted. Rejected: `, dropped);
|
||||||
|
|
||||||
return updates;
|
return updates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user