fix: receipts, cached places, chat previews and the Google-route tool

Saving an expense twice while its receipt is also attached to a place and a
booking hit the new unique index on (file, expense): the row kept from the
first save was skipped, the next spare link row was adopted into a duplicate
pair, and the constraint threw inside the transaction. The whole edit rolled
back with a 500, every time, so that expense could never be changed again. The
adopt now skips a link the expense already holds, and a receipt named twice in
one save is linked once.

The offline place cache was keyed on the place id alone while it is owned and
evicted per trip, so two trips over the same city took each other's rows: the
second write claimed them, switching the second trip off deleted them for both,
and the first trip's fingerprint still matched so nothing ever refilled them.
Offline search then answered nothing for a trip whose switch read "on". Each
trip keeps its own copies now, and the upgrade clears the fingerprints so the
next sync refills what the rebuild dropped.

The chat composer minted its object URLs inside a state updater, which React
runs twice in development, so one picked image drew two thumbnails and removing
one left a preview for a picture that would not be sent. File and URL are one
record now and every mutator commits a finished list.

import_google_maps_route wrote up to thirty places and their day assignments
under trips:write, which does not imply the places:write that create_place is
gated on, and it was the one non-admin write tool with no demo gate and the
only tool in the repo with no annotations. All three corrected.
This commit is contained in:
Maurice
2026-09-13 22:55:15 +02:00
parent f0e4c9a33d
commit 9deedb80ea
9 changed files with 292 additions and 54 deletions
+20 -1
View File
@@ -178,7 +178,7 @@ class TrekOfflineDb extends Dexie {
syncMeta!: Table<SyncMeta, number>;
blobCache!: Table<BlobCacheEntry, string>;
importFiles!: Table<ImportSourceFile, [string, string]>;
areaPlaces!: Table<CachedAreaPlace, string>;
areaPlaces!: Table<CachedAreaPlace, [string, number]>;
constructor(name: string = ANON_DB_NAME) {
super(name);
@@ -227,6 +227,25 @@ class TrekOfflineDb extends Dexie {
this.version(5).stores({
areaPlaces: 'gers, tripId, searchName',
});
// v7/v8: the same place near two trips is two rows now.
//
// Keyed on the GERS id alone, one row could only ever name one trip, and a
// bulkPut for the second trip rewrote the first trip's rows to point at it.
// Switching the second trip off then deleted the shared set by tripId, and
// the first trip's areaPlacesKey still matched its bbox, so nothing ever
// downloaded them again: a trip whose switch read "on" with no offline
// search behind it. Dexie cannot change a primary key in place, so the
// table is dropped and rebuilt, and every stored fingerprint is cleared so
// the next sync refills what the drop took.
this.version(7).stores({ areaPlaces: null });
this.version(8).stores({
areaPlaces: '[gers+tripId], gers, tripId, searchName',
}).upgrade(async (tx) => {
await tx.table('syncMeta').toCollection().modify((row: { areaPlacesKey?: string }) => {
delete row.areaPlacesKey;
});
});
}
}