Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/screens/FlightScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,15 @@ export default function FlightScreen() {
const isPinned = flightId !== null && flightId === pinnedFlightId;

const normFn = normalizeFlightNumber(flightNumber);
const smFlight = activeTab === 'departures'
? staffMonitorDeps.find(sm => sm.flightNumber === normFn)
: staffMonitorArrs.find(sm => sm.flightNumber === normFn);
const normalizeForMatching = (s: string) => s.replace(/[\s\-_]/g, '').toUpperCase();
const normFnStripped = normalizeForMatching(normFn);
const smPool = activeTab === 'departures' ? staffMonitorDeps : staffMonitorArrs;
const smFlight =
smPool.find(sm => sm.flightNumber === normFn) ??
smPool.find(sm => normalizeForMatching(sm.flightNumber) === normFnStripped);
Comment on lines +587 to +592
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renderFlight now does up to two linear scans of smPool per rendered item. With a non-trivial number of flights this becomes O(renderedFlights × staffMonitorFlights) work during renders. Consider precomputing a lookup map (exact and stripped keys) with useMemo when staffMonitorDeps/Arrs changes, and then doing O(1) lookups inside renderFlight.

Copilot uses AI. Check for mistakes.
if (__DEV__ && !smFlight && smPool.length > 0) {
console.log(`[FlightScreen] No staffMonitor match for "${normFn}" (stripped: "${normFnStripped}") in ${activeTab}`);
}

return (
<SwipeableFlightCard
Expand Down
16 changes: 12 additions & 4 deletions src/utils/staffMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export async function fetchStaffMonitorData(nature: 'D' | 'A'): Promise<StaffMon
try {
const url = `https://servizi.pisa-airport.com/staffMonitor/staffMonitor?trans=true&nature=${nature}`;
const resp = await fetch(url);
if (!resp.ok) return [];
if (!resp.ok) {
console.warn(`[staffMonitor] HTTP error for nature=${nature}: ${resp.status} ${resp.statusText}`);
return [];
}
Comment on lines +50 to +53
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchStaffMonitorData is polled every 60s (see FlightScreen effect), so logging on every non-2xx response can spam production device logs when the endpoint is down. Consider gating this warning behind __DEV__, or rate-limiting/deduping (e.g., log only on status change / first failure within a window).

Copilot uses AI. Check for mistakes.
const html = await resp.text();

const results: StaffMonitorFlight[] = [];
Expand All @@ -56,8 +59,8 @@ export async function fetchStaffMonitorData(nature: 'D' | 'A'): Promise<StaffMon

while ((match = trRegex.exec(html)) !== null) {
const rowHTML = match[1];
// Only rows that carry a flight number cell
if (!/class="clsFlight"/i.test(rowHTML) && !/class='clsFlight'/i.test(rowHTML)) continue;
// Only rows that carry a flight number cell (match clsFlight as a substring of the class attribute)
if (!/class\s*=\s*["'][^"']*clsFlight[^"']*["']/i.test(rowHTML)) continue;

const cells = extractTDCells(rowHTML);
if (cells.length < 2) continue;
Expand All @@ -83,8 +86,13 @@ export async function fetchStaffMonitorData(nature: 'D' | 'A'): Promise<StaffMon
}
}

if (__DEV__) {
console.log(`[staffMonitor] nature=${nature} parsed ${results.length} flights.`, results.slice(0, 5).map(r => r.flightNumber));
}

return results;
} catch {
} catch (e) {
console.error(`[staffMonitor] fetch/parse error for nature=${nature}:`, e);
return [];
Comment on lines +94 to 96
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this function runs on a 60s interval, emitting console.error on every exception can produce a large volume of logs in production during outages/parsing changes. Consider __DEV__-gating, rate-limiting, or tracking last-error time/message to avoid repeated identical logs.

Copilot uses AI. Check for mistakes.
}
}
Loading