mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 09:51:14 +00:00
[AZ-376] [AZ-378] [AZ-379] [AZ-380] Repo cleanup: dead code, logger discipline, ColumnList consts
Batch 23 of refactor 03-code-quality-refactoring (4 tasks, 5 SP):
- AZ-376 (C23): Delete unused FindExistingTileAsync from
ITileRepository / TileRepository. No callers; method also took the
obsolete `version` arg removed by C06/AZ-357.
- AZ-378 (C25): Repository _logger discipline.
TileRepository.GetTilesByRegionAsync now emits LogWarning when the
query exceeds SlowQueryThresholdMs (500 ms). RegionRepository and
RouteRepository drop the unused ILogger<TRepo> field, parameter, and
using; Program.cs DI registrations updated.
- AZ-379 (C26): Extract `private const string ColumnList` per repo
(TileRepository, RegionRepository, RouteRepository); SELECTs use
$@"SELECT {ColumnList} FROM ..." (C# 10+ const interpolation).
INSERT/UPDATE/DELETE unchanged; route_points single-site SELECT left
inline.
- AZ-380 (C27): Delete dead alias GeoUtils.CalculatePolygonDiagonalDistance.
Tests: +9 new (RepositoryRefactorTests x8, GeoUtilsRefactorTests x1)
covering each AC via reflection / file-content assertions; pattern
mirrors ToolingConfigurationTests (b22) and AcceptanceCriteriaRT2Tests
(b19). Unit suite 181 -> 190, all green. dotnet format clean.
Code review: PASS_WITH_WARNINGS (3 Low findings, all informational or
out-of-scope for this batch). See
_docs/03_implementation/reviews/batch_23_review.md.
Cumulative review counter 2/3; next K=3 review fires after batch 24.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npgsql;
|
||||
@@ -7,6 +8,14 @@ namespace SatelliteProvider.DataAccess.Repositories;
|
||||
|
||||
public class TileRepository : ITileRepository
|
||||
{
|
||||
private const int SlowQueryThresholdMs = 500;
|
||||
|
||||
private const string ColumnList = @"id, tile_zoom as TileZoom, tile_x as TileX, tile_y as TileY,
|
||||
latitude, longitude,
|
||||
tile_size_meters as TileSizeMeters, tile_size_pixels as TileSizePixels,
|
||||
image_type as ImageType, maps_version as MapsVersion, version,
|
||||
file_path as FilePath, created_at as CreatedAt, updated_at as UpdatedAt";
|
||||
|
||||
private readonly string _connectionString;
|
||||
private readonly ILogger<TileRepository> _logger;
|
||||
|
||||
@@ -19,13 +28,9 @@ public class TileRepository : ITileRepository
|
||||
public async Task<TileEntity?> GetByIdAsync(Guid id)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
const string sql = @"
|
||||
SELECT id, tile_zoom as TileZoom, tile_x as TileX, tile_y as TileY,
|
||||
latitude, longitude,
|
||||
tile_size_meters as TileSizeMeters, tile_size_pixels as TileSizePixels,
|
||||
image_type as ImageType, maps_version as MapsVersion, version,
|
||||
file_path as FilePath, created_at as CreatedAt, updated_at as UpdatedAt
|
||||
FROM tiles
|
||||
const string sql = $@"
|
||||
SELECT {ColumnList}
|
||||
FROM tiles
|
||||
WHERE id = @Id";
|
||||
|
||||
return await connection.QuerySingleOrDefaultAsync<TileEntity>(sql, new { Id = id });
|
||||
@@ -34,13 +39,9 @@ public class TileRepository : ITileRepository
|
||||
public async Task<TileEntity?> GetByTileCoordinatesAsync(int tileZoom, int tileX, int tileY)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
const string sql = @"
|
||||
SELECT id, tile_zoom as TileZoom, tile_x as TileX, tile_y as TileY,
|
||||
latitude, longitude,
|
||||
tile_size_meters as TileSizeMeters, tile_size_pixels as TileSizePixels,
|
||||
image_type as ImageType, maps_version as MapsVersion, version,
|
||||
file_path as FilePath, created_at as CreatedAt, updated_at as UpdatedAt
|
||||
FROM tiles
|
||||
const string sql = $@"
|
||||
SELECT {ColumnList}
|
||||
FROM tiles
|
||||
WHERE tile_zoom = @TileZoom AND tile_x = @TileX AND tile_y = @TileY
|
||||
ORDER BY updated_at DESC
|
||||
LIMIT 1";
|
||||
@@ -48,33 +49,6 @@ public class TileRepository : ITileRepository
|
||||
return await connection.QuerySingleOrDefaultAsync<TileEntity>(sql, new { TileZoom = tileZoom, TileX = tileX, TileY = tileY });
|
||||
}
|
||||
|
||||
public async Task<TileEntity?> FindExistingTileAsync(double latitude, double longitude, double tileSizeMeters, int zoomLevel, int version)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
const string sql = @"
|
||||
SELECT id, tile_zoom as TileZoom, tile_x as TileX, tile_y as TileY,
|
||||
latitude, longitude,
|
||||
tile_size_meters as TileSizeMeters, tile_size_pixels as TileSizePixels,
|
||||
image_type as ImageType, maps_version as MapsVersion, version,
|
||||
file_path as FilePath, created_at as CreatedAt, updated_at as UpdatedAt
|
||||
FROM tiles
|
||||
WHERE ABS(latitude - @Latitude) < 0.0001
|
||||
AND ABS(longitude - @Longitude) < 0.0001
|
||||
AND ABS(tile_size_meters - @TileSizeMeters) < 1
|
||||
AND tile_zoom = @TileZoom
|
||||
AND version = @Version
|
||||
LIMIT 1";
|
||||
|
||||
return await connection.QuerySingleOrDefaultAsync<TileEntity>(sql, new
|
||||
{
|
||||
Latitude = latitude,
|
||||
Longitude = longitude,
|
||||
TileSizeMeters = tileSizeMeters,
|
||||
TileZoom = zoomLevel,
|
||||
Version = version
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TileEntity>> GetTilesByRegionAsync(double latitude, double longitude, double sizeMeters, int zoomLevel)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
@@ -90,19 +64,16 @@ public class TileRepository : ITileRepository
|
||||
var latRange = expandedSizeMeters / 111000.0;
|
||||
var lonRange = expandedSizeMeters / (111000.0 * Math.Cos(latitude * Math.PI / 180.0));
|
||||
|
||||
const string sql = @"
|
||||
SELECT id, tile_zoom as TileZoom, tile_x as TileX, tile_y as TileY,
|
||||
latitude, longitude,
|
||||
tile_size_meters as TileSizeMeters, tile_size_pixels as TileSizePixels,
|
||||
image_type as ImageType, maps_version as MapsVersion, version,
|
||||
file_path as FilePath, created_at as CreatedAt, updated_at as UpdatedAt
|
||||
FROM tiles
|
||||
const string sql = $@"
|
||||
SELECT {ColumnList}
|
||||
FROM tiles
|
||||
WHERE latitude BETWEEN @MinLat AND @MaxLat
|
||||
AND longitude BETWEEN @MinLon AND @MaxLon
|
||||
AND tile_zoom = @TileZoom
|
||||
ORDER BY latitude DESC, longitude ASC, updated_at DESC";
|
||||
|
||||
return await connection.QueryAsync<TileEntity>(sql, new
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
var tiles = await connection.QueryAsync<TileEntity>(sql, new
|
||||
{
|
||||
MinLat = latitude - latRange / 2,
|
||||
MaxLat = latitude + latRange / 2,
|
||||
@@ -110,6 +81,16 @@ public class TileRepository : ITileRepository
|
||||
MaxLon = longitude + lonRange / 2,
|
||||
TileZoom = zoomLevel
|
||||
});
|
||||
stopwatch.Stop();
|
||||
|
||||
if (stopwatch.ElapsedMilliseconds > SlowQueryThresholdMs)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Slow GetTilesByRegionAsync: {ElapsedMs} ms (threshold {ThresholdMs} ms) for lat={Latitude}, lon={Longitude}, sizeMeters={SizeMeters}, zoom={ZoomLevel}",
|
||||
stopwatch.ElapsedMilliseconds, SlowQueryThresholdMs, latitude, longitude, sizeMeters, zoomLevel);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
public async Task<Guid> InsertAsync(TileEntity tile)
|
||||
|
||||
Reference in New Issue
Block a user