🐛 Filter old passages
Only passages with a expectedDepartTs > now - 60s are kept.
This commit is contained in:
@@ -52,11 +52,29 @@ export function BusinessDataProvider(props: { children: JSX.Element }) {
|
||||
return store.passages;
|
||||
}
|
||||
|
||||
const _cleanupPassages = (passages: Passages): void => {
|
||||
const deadline = Math.floor(Date.now() / 1000) - 60;
|
||||
for (const linePassages of Object.values(passages)) {
|
||||
for (const destination of Object.keys(linePassages)) {
|
||||
const destinationPassages = linePassages[destination];
|
||||
const cleaned = [];
|
||||
for (const passage of destinationPassages) {
|
||||
if (passage.expectedDepartTs > deadline) {
|
||||
cleaned.push(passage);
|
||||
}
|
||||
}
|
||||
linePassages[destination] = cleaned;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const refreshPassages = async (stopId: number): Promise<void> => {
|
||||
const httpOptions = { headers: { "Content-Type": "application/json" } };
|
||||
console.log(`Fetching data for ${stopId}`);
|
||||
const data = await fetch(`${serverUrl()}/stop/nextPassages/${stopId}`, httpOptions);
|
||||
const response = await data.json();
|
||||
_cleanupPassages(response.passages);
|
||||
addPassages(response.passages);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user