mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 17:11:15 +00:00
51b572108a
Captures the post-implementation autodev gates for AZ-484 multi-source tile storage: - Step 12 (Test-Spec Sync): added 7 AC rows (AZ-484 AC-1..AC-7) and a PT-07 NFR row to traceability-matrix.md; added PT-07 scenario to performance-tests.md. - Step 13 (Update Docs): refreshed data_model.md (tiles columns + indexes + selection rule + UPSERT contract + migrations 012/013), module-layout.md (Common/Enums section with L-001 guidance, DataAccess imports-from now lists 6 sites), 6 module / component docs to reflect the new repo signatures, source/captured_at fields, and Dapper enum bypass workaround. ripple_log_cycle1.md records zero out-of-scope ripple. - Step 14 (Security Audit): PASS_WITH_WARNINGS - 0 Critical, 0 High, 5 Medium, 5 Low. AZ-484 itself added zero new findings. Hardening items (Postgres default creds, .env in build context, GMaps key rotation, ASP.NET Core 8.0.21 -> 8.0.25, rate limiter) recorded for separate tickets. - Step 15 (Performance Test): all PT-01..PT-07 scenarios Unverified (non-blocking); PT-07 baseline-comparison harness deferred to a leftover for next cycle. - Step 16 (Deploy): cycle deploy report covering migration safety, rollback path, post-deploy verification, security caveats. Co-authored-by: Cursor <cursoragent@cursor.com>
3.5 KiB
3.5 KiB
Module: DataAccess/Repositories/TileRepository
Purpose
Dapper-based repository for the tiles table. Handles CRUD operations and spatial queries for satellite tile records.
Public Interface
ITileRepository (interface)
GetByIdAsync(Guid id) → Task<TileEntity?>GetByTileCoordinatesAsync(int tileZoom, int tileX, int tileY) → Task<TileEntity?>: finds the most-recent tile across all sources for the given slippy coordinates. Selection rule:ORDER BY captured_at DESC, updated_at DESC, id DESC LIMIT 1(AZ-484 v1.0.0 contract).GetTilesByRegionAsync(double lat, double lon, double sizeMeters, int zoomLevel) → Task<IEnumerable<TileEntity>>: spatial bounding box query (expanded by 2 × tile size to cover edges); appliesDISTINCT ON (latitude, longitude, tile_zoom, tile_size_meters)per AZ-484 to return at most one row per cell — the most-recent across sources — preserving the historical caller-facing orderlatitude DESC, longitude ASC.InsertAsync(TileEntity tile) → Task<Guid>: per-source UPSERT —ON CONFLICT (latitude, longitude, tile_zoom, tile_size_meters, source) DO UPDATE file_path, tile_x, tile_y, captured_at, updated_at(AZ-484 5-column unique key).UpdateAsync(TileEntity tile) → Task<int>: full row update byidincludingsourceandcaptured_at.DeleteAsync(Guid id) → Task<int>
TileRepository (implementation)
Constructs a new NpgsqlConnection per method call (no connection pooling at the repository level; Npgsql pools connections internally). Logs a Slow GetTilesByRegionAsync warning when the region query exceeds 500 ms.
Internal Logic
GetTilesByRegionAsynccalculates a bounding box by expanding the requested region by 2 × tile size to ensure edge tiles are included. Uses meters-to-degrees approximation viaGeoUtils(post-AZ-377 — single source of truth for Earth constants).InsertAsyncuses a per-source UPSERT pattern keyed on the 5-column unique indexidx_tiles_unique_location_source(created by migration 013). Two producers (e.g.,google_maps+uav) coexist for the same cell; same-source re-insert refreshescaptured_atandupdated_at.GetByTileCoordinatesAsyncandGetTilesByRegionAsyncapply the AZ-484 selection rule: most-recent across sources, deterministic tie-break on(captured_at DESC, updated_at DESC, id DESC).TileEntity.Sourceis a plainstringstoring the snake_case wire value ('google_maps'|'uav'); enum<->wire conversion happens viaSatelliteProvider.Common.Enums.TileSourceConverter. This avoids Dapper issue #259 (TypeHandler bypass for enum reads — see_docs/LESSONS.mdL-001).FindExistingTileAsyncwas removed by AZ-376 (see_docs/04_refactoring/03-code-quality-refactoring/).
Dependencies
- NuGet:
Dapper,Npgsql SatelliteProvider.DataAccess.Models.TileEntitySatelliteProvider.Common.GeoUtils(Earth constants / meters-to-degrees)Microsoft.Extensions.Logging
Contract
Implements the frozen v1.0.0 contract _docs/02_document/contracts/data-access/tile-storage.md. Schema invariants Inv-1..Inv-5 are enforced here (UPSERT key, selection rule, source value space).
Consumers
TileService— all read/write operationsProgram.cs(ServeTile, GetTileByLatLon handlers) —GetByTileCoordinatesAsync,InsertAsync
Data Models
Operates on TileEntity.
Configuration
Receives connection string via constructor.
External Integrations
PostgreSQL — SQL queries via Dapper + Npgsql.
Security
None.
Tests
No dedicated repository tests.