Skip to content

Conversation

@maltehuebner
Copy link
Contributor

Summary

  • Remove dead code in refreshMaterializedView()
  • Optimize findDataForCoronaFireworksAnalysis() query using CTE

Changes

refreshMaterializedView()

Removed unused SQL statements that were being overwritten. Only current_data view refresh was actually executed.

findDataForCoronaFireworksAnalysis()

Refactored the query to use a Common Table Expression (CTE) to avoid redundant ST_MakePoint() calculations:

Before: 6 parameters (same coordinates passed 3 times)

WHERE station_id IN (SELECT id FROM station WHERE coord <-> ST_MakePoint(?, ?) < 2 
                     ORDER BY coord <-> ST_MakePoint(?, ?) ASC)
ORDER BY ..., coord <-> ST_MakePoint(?, ?) ASC, ...

After: 2 parameters with CTE

WITH search_point AS (
    SELECT ST_MakePoint(?, ?) AS point
),
nearby_stations AS (
    SELECT s.id, s.coord <-> (SELECT point FROM search_point) AS dist
    FROM station s
    WHERE s.coord <-> (SELECT point FROM search_point) < 2
    ORDER BY dist ASC
)
SELECT ... FROM silvester_data sd
INNER JOIN nearby_stations ns ON ns.id = sd.station_id
...

Benefits

  • Cleaner, more maintainable code
  • Single point of coordinate definition
  • Pre-calculated distances available for sorting
  • JOIN instead of IN subquery for better query plan optimization

Test plan

  • Test Corona/Silvester analysis page with various coordinates
  • Verify materialized view refresh command works correctly

🤖 Generated with Claude Code

- Remove dead code in refreshMaterializedView() (unused view refresh statements)
- Optimize findDataForCoronaFireworksAnalysis() using CTE to avoid redundant
  ST_MakePoint calculations (reduced from 6 to 2 parameters)
- Use INNER JOIN with pre-calculated distances instead of subquery with IN clause

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@maltehuebner maltehuebner self-assigned this Jan 29, 2026
@maltehuebner maltehuebner added php Pull requests that update Php code AI-generated labels Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-generated php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant