Fix issue with db error
Tests / backend-test (pull_request) Successful in 6s
Tests / frontend-test (pull_request) Failing after 9s
Tests / e2e-test (pull_request) Failing after 1m30s

This commit is contained in:
(jenkins)
2026-04-17 00:41:41 +01:00
parent 8890e64d0e
commit 8d646ecd74
+6 -4
View File
@@ -68,10 +68,13 @@ app.get('/api/line-of-sight', async (req, res) => {
// Bulk land check: use a single query for all points to avoid connection pool exhaustion
const waterStart = Date.now();
const lons = pathPoints.map(p => p.lon);
const lats = pathPoints.map(p => p.lat);
const waterCheckQuery = `
WITH points AS (
SELECT i, ST_SetSRID(ST_MakePoint(val[1], val[2]), 4326)::geography as p_geom
FROM unnest($1::float8[][]) WITH ORDINALITY AS t(val, i)
SELECT i, ST_SetSRID(ST_MakePoint(lon, lat), 4326)::geography as p_geom
FROM unnest($1::float8[], $2::float8[]) WITH ORDINALITY AS t(lon, lat, i)
)
SELECT i, EXISTS (
SELECT 1 FROM cities
@@ -82,8 +85,7 @@ app.get('/api/line-of-sight', async (req, res) => {
ORDER BY i;
`;
const pointsArray = pathPoints.map(p => [p.lon, p.lat]);
const waterResults = await pool.query(waterCheckQuery, [pointsArray]);
const waterResults = await pool.query(waterCheckQuery, [lons, lats]);
const waterChecks = waterResults.rows.map(r => !r.has_land);
console.log(`Bulk water check completed in ${Date.now() - waterStart}ms for ${pathPoints.length} points.`);