Cache ADSB/AIS calls

This commit is contained in:
2026-06-27 19:39:14 -04:00
parent 3838a73e75
commit ce86fdfcc8
4 changed files with 21 additions and 9 deletions

View File

@@ -8,6 +8,10 @@ const SENDER_TYPE = {
12: 'AtoN', 13: 'SART/EPIRB'
};
let aisCache = null;
let aisCacheTs = 0;
const AIS_TTL = 1000;
function decodeMsgTypes(raw) {
const types = [];
for (let i = 0; i < 32; i++) {
@@ -38,6 +42,7 @@ function decodeFlags(flags) {
}
export async function getAIS() {
if (aisCache && Date.now() - aisCacheTs < AIS_TTL) return aisCache;
const {ADSB_URL} = cfg();
if (!ADSB_URL) return {data: []};
const r = await fetch(`${ADSB_URL}:9990/api/ships_array.json`);
@@ -45,7 +50,7 @@ export async function getAIS() {
const staticMap = new Map(staticRows.map(row => [row[0], row]));
return dynamic.map(row => {
aisCache = dynamic.map(row => {
const [mmsi, lat, lon, distance, bearing, heading,
cog, speed, status, rrsi, ppm, count, msg_type,
last_signal, last_group, group_mask, flags, altitude,
@@ -79,4 +84,6 @@ export async function getAIS() {
status
};
});
aisCacheTs = Date.now();
return aisCache;
}