fix(places): read the dedup tracks off the dedup inputs, the places files stay within their size entries

This commit is contained in:
Maurice
2026-10-26 14:18:59 +01:00
parent e677d58f91
commit 313198ba63
6 changed files with 21 additions and 40 deletions
@@ -590,12 +590,6 @@ export class PlacesRepository extends TrekRepository<Places> {
.execute<{ name: string; description: string | null; address: string | null; lat: number | null; lng: number | null; route_geometry: string | null; category: string | null }[]>('all', false);
}
/** The names of the trip's places that carry a line, which a track to import is matched against (#2810). */
async listTrackNames(trip_id: number): Promise<string[]> {
const rows = await this.find({ trip: trip_id, route_geometry: { $ne: null } }, { fields: ['name'] });
return rows.map((row) => row.name);
}
/**
* PL24 (`PlacesService.buildDedupSet`'s read) — `SELECT name, lat, lng,
* google_place_id, google_ftid, osm_id, amap_poi_id FROM places WHERE
@@ -611,16 +605,15 @@ export class PlacesRepository extends TrekRepository<Places> {
* it was.
*/
async listDedupInputs(trip_id: string): Promise<{
name: string | null; lat: number | null; lng: number | null;
name: string | null; lat: number | null; lng: number | null; route_geometry: string | null;
google_place_id: string | null; google_ftid: string | null; osm_id: string | null; amap_poi_id: string | null;
}[]> {
// route_geometry tells a track from a pin: a track to import matches only tracks (#2810).
return this.qb('p')
.select(['p.name', 'p.lat', 'p.lng', 'p.google_place_id', 'p.google_ftid', 'p.osm_id', 'p.amap_poi_id'])
.select(['p.name', 'p.lat', 'p.lng', 'p.route_geometry',
'p.google_place_id', 'p.google_ftid', 'p.osm_id', 'p.amap_poi_id'])
.where('p.trip_id = ?', [trip_id])
.execute<{
name: string | null; lat: number | null; lng: number | null;
google_place_id: string | null; google_ftid: string | null; osm_id: string | null; amap_poi_id: string | null;
}[]>('all', false);
.execute<Awaited<ReturnType<PlacesRepository['listDedupInputs']>>>('all', false);
}
/**
+6 -4
View File
@@ -137,23 +137,25 @@ export function isPlaceDuplicate(candidate: DedupCandidate, dedup: DedupSet): bo
*/
export function dedupSetOf(
rows: ReadonlyArray<
{ name: string | null; lat: number | null; lng: number | null } & Parameters<typeof externalIdsOf>[0]
{ name: string | null; lat: number | null; lng: number | null; route_geometry?: string | null } & Parameters<
typeof externalIdsOf
>[0]
>,
trackNames: ReadonlyArray<string | null> = [],
): DedupSet {
const names = new Set<string>();
const trackNames = new Set<string>();
const coords: Array<{ lat: number; lng: number }> = [];
const externalIds = new Set<string>();
for (const row of rows) {
for (const id of externalIdsOf(row)) externalIds.add(id);
if (row.name) {
names.add(row.name.trim().toLowerCase());
if (row.route_geometry) trackNames.add(row.name.trim().toLowerCase());
} else if (row.lat != null && row.lng != null) {
coords.push({ lat: row.lat, lng: row.lng });
}
}
const tracks = trackNames.map(normalizePlaceName).filter((name): name is string => !!name);
return { names, trackNames: new Set(tracks), coords, externalIds };
return { names, trackNames, coords, externalIds };
}
/** Record a newly inserted place so subsequent candidates in the same batch are checked against it. */
+1 -1
View File
@@ -751,7 +751,7 @@ export class PlacesService {
/** Build a lookup of names/coords for places already in a trip. */
private async buildDedupSet(tripId: string): Promise<DedupSet> {
// PL24 — `PlacesRepository.listDedupInputs` replaces the raw statement (Task 5 review L6 ruling).
return dedupSetOf(await this.placesRepo.listDedupInputs(tripId), await this.placesRepo.listTrackNames(toRowId(tripId) ?? -1));
return dedupSetOf(await this.placesRepo.listDedupInputs(tripId));
}
/** Which prepared GPX rows the import would skip as already in the trip: its own rule, read only. */