The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(places): read the dedup tracks off the dedup inputs, the places files stay within their size entries
Maurice313198ba6369
diff --git a/server/scripts/size-baseline.json b/server/scripts/size-baseline.jsonindex 934b2cc4a..d36978050 100644--- a/server/scripts/size-baseline.json+++ b/server/scripts/size-baseline.json@@ -1,7 +1,7 @@{"scripts/db-call-graph.mjs": 1036,"scripts/generate-entities.ts": 2259,- "src/db/repositories/Places.repository.ts": 1439,+ "src/db/repositories/Places.repository.ts": 1438,"src/db/repositories/Reservations.repository.ts": 1604,"src/db/repositories/Trips.repository.ts": 1121,"src/db/repositories/Users.repository.ts": 1445,diff --git a/server/src/db/repositories/Places.repository.ts b/server/src/db/repositories/Places.repository.tsindex f1fa5d469..bb7029cae 100644--- a/server/src/db/repositories/Places.repository.ts+++ b/server/src/db/repositories/Places.repository.ts@@ -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);}/**diff --git a/server/src/nest/places/places.helpers.ts b/server/src/nest/places/places.helpers.tsindex 491e555e4..a2dce9617 100644--- a/server/src/nest/places/places.helpers.ts+++ b/server/src/nest/places/places.helpers.ts@@ -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. */diff --git a/server/src/nest/places/places.service.ts b/server/src/nest/places/places.service.tsindex 1fb206035..33e0b2027 100644--- a/server/src/nest/places/places.service.ts+++ b/server/src/nest/places/places.service.ts@@ -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. */diff --git a/server/tests/unit/db/repositories/Places.repository.test.ts b/server/tests/unit/db/repositories/Places.repository.test.tsindex 311d9394c..e75f963bb 100644--- a/server/tests/unit/db/repositories/Places.repository.test.ts+++ b/server/tests/unit/db/repositories/Places.repository.test.ts@@ -574,20 +574,21 @@ describe('PlacesRepository.listForGpx (PL29) and existsByImageUrl (PI1)', () =>* by, the service-level dedup tests.*/describe('PlacesRepository.listDedupInputs (PL24)', () => {- it('PLACEREPO-048: projects exactly the seven dedup columns, scoped to the trip', async () => {+ it('PLACEREPO-048: projects exactly the eight dedup columns, the line included (#2810), scoped to the trip', async () => {const { user } = createUser(testDb);const trip = createTrip(testDb, user.id);const other = createTrip(testDb, user.id);await insertRow(t.orm, Places, {trip: trip.id, name: 'Louvre', lat: 48.86, lng: 2.34, google_place_id: 'gp1', google_ftid: 'ft1', osm_id: 'osm1', amap_poi_id: 'amap1',+ route_geometry: '[[48.86,2.34],[48.87,2.35]]',});await insertRow(t.orm, Places, { trip: trip.id, name: '', lat: 1.1, lng: 2.2 });createPlace(testDb, other.id, { name: 'Not this trip' });const rows = await places.listDedupInputs(String(trip.id));expect(rows).toEqual([- { name: 'Louvre', lat: 48.86, lng: 2.34, google_place_id: 'gp1', google_ftid: 'ft1', osm_id: 'osm1', amap_poi_id: 'amap1' },- { name: '', lat: 1.1, lng: 2.2, google_place_id: null, google_ftid: null, osm_id: null, amap_poi_id: null },+ { name: 'Louvre', lat: 48.86, lng: 2.34, route_geometry: '[[48.86,2.34],[48.87,2.35]]', google_place_id: 'gp1', google_ftid: 'ft1', osm_id: 'osm1', amap_poi_id: 'amap1' },+ { name: '', lat: 1.1, lng: 2.2, route_geometry: null, google_place_id: null, google_ftid: null, osm_id: null, amap_poi_id: null },]);});@@ -1587,16 +1588,4 @@ describe('PlacesRepository.isTour / listForTrip tour_place_id', () => {expect(byId.get(tour.id)).toBe(tour.id);expect(byId.get(plain.id)).toBeNull();});-- it("PLACEREPO-TOUR-005: listTrackNames lists the names of the trip's places with a line (#2810)", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const other = createTrip(testDb, user.id);- const line = '[[49,12],[49.01,12.01]]';- const tracks = [createPlace(testDb, trip.id, { name: 'Garmin hike' }), createPlace(testDb, trip.id, { name: 'Ridge walk' }), createPlace(testDb, other.id, { name: 'Elsewhere' })];- await updateRows(t.orm, Places, { id: { $in: tracks.map((p) => p.id) } }, { route_geometry: line });- createPlace(testDb, trip.id, { name: 'Hokitika Gorge' });-- expect((await places.listTrackNames(trip.id)).sort()).toEqual(['Garmin hike', 'Ridge walk']);- });});diff --git a/server/tests/unit/nest/places.helpers.test.ts b/server/tests/unit/nest/places.helpers.test.tsindex e02231bdf..30d1cd2e6 100644--- a/server/tests/unit/nest/places.helpers.test.ts+++ b/server/tests/unit/nest/places.helpers.test.ts@@ -28,13 +28,10 @@ const emptyDedup = (): DedupSet => ({ names: new Set(), coords: [], externalIds:describe('isPlaceDuplicate / trackInsertedInDedupSet', () => {it('matches a track only against the tracks of that name, never a sight of that name (#2810)', () => {// The watch named the hike after the gorge, and the gorge is already a place of the trip.- const dedup = dedupSetOf(- [- { name: 'Hokitika Gorge', lat: -42.95, lng: 171.0 },- { name: '008', lat: 1, lng: 2 },- ],- [' 008 ', null],- );+ const dedup = dedupSetOf([+ { name: 'Hokitika Gorge', lat: -42.95, lng: 171.0, route_geometry: null },+ { name: ' 008 ', lat: 1, lng: 2, route_geometry: '[[1,2],[3,4]]' },+ ]);expect(isPlaceDuplicate({ name: 'hokitika gorge', lat: -42.9, lng: 171.0, track: true }, dedup)).toBe(false);expect(isPlaceDuplicate({ name: '008', lat: 1, lng: 2, track: true }, dedup)).toBe(true);// A pin still matches every place of its name, a track included.