From b33fe35c4b300c68fb706709d3c446fbe8762348 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Sat, 28 Mar 2026 15:15:13 +0200 Subject: [PATCH] perf(martin+postgres): connection pool limit + compound indexes + minzoom alignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Martin: pool_size=8 (prevents overwhelming PostgreSQL with concurrent queries) - Martin: gis_terenuri minzoom 10→14, gis_cladiri minzoom 12→15 (PMTiles serves z0-z14, no point in Martin generating those) - PostGIS: add compound index layerId+geom for Martin view queries - PostGIS: add B-tree index on layerId for LIKE filtering in views Fixes 90% CPU on PostgreSQL during cold tile loads at detail zoom levels. Co-Authored-By: Claude Opus 4.6 (1M context) --- martin.yaml | 5 +++-- prisma/postgis-setup.sql | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/martin.yaml b/martin.yaml index c68fdfd..2dba2ae 100644 --- a/martin.yaml +++ b/martin.yaml @@ -4,6 +4,7 @@ postgres: connection_string: ${DATABASE_URL} + pool_size: 8 default_srid: 3844 auto_publish: false tables: @@ -83,7 +84,7 @@ postgres: geometry_column: geom srid: 3844 bounds: [20.2, 43.5, 30.0, 48.3] - minzoom: 10 + minzoom: 14 maxzoom: 18 properties: object_id: text @@ -138,7 +139,7 @@ postgres: geometry_column: geom srid: 3844 bounds: [20.2, 43.5, 30.0, 48.3] - minzoom: 12 + minzoom: 15 maxzoom: 18 properties: object_id: text diff --git a/prisma/postgis-setup.sql b/prisma/postgis-setup.sql index 1553627..c78ae38 100644 --- a/prisma/postgis-setup.sql +++ b/prisma/postgis-setup.sql @@ -59,6 +59,14 @@ WHERE geometry IS NOT NULL AND geom IS NULL; CREATE INDEX IF NOT EXISTS gis_feature_geom_idx ON "GisFeature" USING GIST (geom); +-- Compound index: layerId + spatial — Martin queries filter by layer via views +CREATE INDEX IF NOT EXISTS gis_feature_layer_geom_idx + ON "GisFeature" ("layerId", geom) WHERE geom IS NOT NULL; + +-- B-tree index on layerId for view filtering (LIKE 'TERENURI%', 'CLADIRI%') +CREATE INDEX IF NOT EXISTS gis_feature_layer_id_idx + ON "GisFeature" ("layerId"); + -- ============================================================================= -- 7. QGIS-friendly views -- - Clean snake_case column names