Skip to content

fix geocode cache key ignoring the geojson variant - #137

Open
munzzyy wants to merge 1 commit into
FoggedLens:masterfrom
munzzyy:fix/geocode-cache-key-geojson
Open

fix geocode cache key ignoring the geojson variant#137
munzzyy wants to merge 1 commit into
FoggedLens:masterfrom
munzzyy:fix/geocode-cache-key-geojson

Conversation

@munzzyy

@munzzyy munzzyy commented Aug 3, 2026

Copy link
Copy Markdown

/geocode and /geocode/multi both go through NominatimClient.geocodePhrase, and they ask for different things. The single endpoint passes includeGeoJson: true so the map can draw the city boundary; the multi endpoint passes false. Both then look the result up under the same cache key:

const cacheKey = `geocode:${query}`;

So whichever endpoint asks first wins that query for the next 24 hours. If /geocode/multi gets there first, a later /geocode for the same place is served the cached entry, which has no geojson on it, and no Nominatim call is made to go get it. Map.vue reads result.geojson to set the boundary polygon and to work out the zoom level, so the search quietly lands on the place with no boundary drawn.

The parameter was added in #109; the cache key is from back when there was only one variant.

The fix puts the variant in the key. I also added a test for the cached path, since there wasn't one.

Verifying

api/services/NominatimClient.test.ts stubs fetch and counts the upstream calls. On master:

$ bun test services/NominatimClient.test.ts
45 |
46 |     await client.geocodePhrase(query, false);
47 |     const withGeoJson = await client.geocodePhrase(query, true);
48 |
49 |     expect(urls.length).toBe(2);
                             ^
error: expect(received).toBe(expected)

Expected: 2
Received: 1

      at <anonymous> (.../api/services/NominatimClient.test.ts:49:25)
(fail) NominatimClient.geocodePhrase > does not serve a cached geojson-free result to a caller that asked for geojson [21.03ms]

 1 pass
 1 fail
 2 expect() calls
Ran 2 tests across 1 file. [271.00ms]

One upstream call instead of two, because the second request came back from the cache.

With the fix, the whole api suite:

$ bun test
bun test v1.3.14 (0d9b296a)

 7 pass
 0 fail
 15 expect() calls
Ran 7 tests across 2 files. [225.00ms]

The second test in the file asks for the same variant twice and still expects a single upstream call, so this isn't just turning the cache off.

One thing worth flagging: the disk store lives at a fixed /tmp/nominatim-cache and outlives the test process, so the tests generate a query string they haven't cached before rather than assuming an empty cache. Happy to swap that for an injectable cache if you'd rather have the seam.

geocodePhrase gained an includeGeoJson parameter in FoggedLens#109, but the cache key
still only used the query. Whichever endpoint asked first won the cache
entry for 24 hours, so /geocode could return a result with no geojson when
/geocode/multi had already cached that query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant