fix(dawarich): name an unnamed stay once Dawarich has geocoded its points

A stay stored as 'Unnamed stay' because none of its points was geocoded yet is now read again on the next sync, so a slow background geocoder or a stay from before the upgrade gets its town once Dawarich knows it.
This commit is contained in:
Maurice
2026-11-23 15:02:08 +01:00
parent a604f84899
commit 1fb1b102e8
2 changed files with 9 additions and 7 deletions
@@ -345,9 +345,10 @@ export class DawarichSyncService {
* What a stay is called. Its own name when Dawarich sent one. Otherwise the
* reverse-geocoded points recorded during it name it (#3105): Dawarich sends
* a placeholder for a visit without a place even when its points know the
* town. A name found earlier is kept while the visit is unchanged, and so is
* the finding that none of its points was geocoded; a stay whose points
* were not read yet keeps the placeholder, which the next run reads again.
* town. A name found earlier is kept while the visit is unchanged. A stay
* none of whose points was geocoded yet is read again on the next run, since
* Dawarich geocodes in the background and can lag behind by days; so is one
* whose points were not read yet, which keeps the placeholder meanwhile.
*/
private async stayName(
visit: { name: string; named: boolean; startedAt: string; endedAt: string },
@@ -356,7 +357,8 @@ export class DawarichSyncService {
nameStay: StayNamer,
): Promise<string> {
if (visit.named) return visit.name;
if (existing?.name && existing.source_hash === hash && !isPlaceholderName(existing.name)) return existing.name;
const kept = existing?.source_hash === hash ? existing.name : null;
if (kept && !isPlaceholderName(kept) && kept !== UNNAMED_STAY) return kept;
const found = await nameStay(visit.startedAt, visit.endedAt);
if (found === undefined) return STAY_NAME_PENDING;
return found ?? UNNAMED_STAY;
@@ -334,15 +334,15 @@ describe('DawarichSyncService, naming a stay Dawarich sends without a name (#310
expect(listGeocodedPoints).not.toHaveBeenCalled();
});
it('DAWARICH-SYNC-093: points without a geocode settle on "Unnamed stay" until the visit changes', async () => {
it('DAWARICH-SYNC-093: points without a geocode yet read "Unnamed stay", and are read again until Dawarich geocodes them', async () => {
withVisits(nameless(904));
await svc.syncUser(USER);
expect((await only()).name).toBe('Unnamed stay');
listGeocodedPoints.mockClear();
listGeocodedPoints.mockResolvedValue([{ city: 'Cinisi', country_name: 'Italy' }]);
await svc.syncUser(USER);
expect(listGeocodedPoints).not.toHaveBeenCalled();
expect((await only()).name).toBe('Cinisi, Italy');
});
it('DAWARICH-SYNC-094: points that could not be read keep the placeholder and are read on the next run', async () => {