mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
Get the pictures right and stop reusing stale answers
Three things you could see on dev1. Pictures were "roughly right" rather than right, because a coordinate search only knows what was photographed within 300 m. Wikidata's P18 is one picture somebody chose to represent that exact object - "Zurletzteninstanz.jpg" for the restaurant, not a statue down the road - so it now leads, then the Commons category, and geosearch is the last resort it should always have been. Small venues carry a wikidata tag far more often than a Commons category, so this is also what reaches the places the other sources miss. Descriptions stayed on Wikipedia after the switch to Wikivoyage because the week-long result cache predates it. It carries a format version now; a release that changes the shape or the sources invalidates its own entries instead of serving last week's for another six days. Ratings and opening hours were being fetched from Google and then dropped on the floor - the fact list only looked at OpenStreetMap tags. Both are shown now, whichever provider supplied them. Also: the column follows a place opened from the map, not only one picked from search. A POI tap arrives as prefillCoords and never touched the selection, so the column kept showing the previously added place. Pictures are a tight three-column grid and only the picture in play is credited in full, on one line. Crediting all of them at two lines each drowned the column, and the licence attaches to the one that gets used - whose credit also stays visible in the inspector after saving. The request carries the place record the dialog already fetched, so the server skips a details lookup it was making in parallel with the client's own. That lookup was measured at 12.8 s for a large OSM relation.
This commit is contained in:
@@ -471,8 +471,10 @@ describe('collectDescription', () => {
|
||||
// ── Result cache ─────────────────────────────────────────────────────────────
|
||||
|
||||
describe('result cache', () => {
|
||||
const cachedRow = (photos: unknown[], fetchedAt = Date.now()) => ({
|
||||
payload_json: JSON.stringify({ photos, description: null }),
|
||||
// v is the cache format version; an entry written before a release that
|
||||
// changes the shape or the sources is discarded rather than served.
|
||||
const cachedRow = (photos: unknown[], fetchedAt = Date.now(), v: number | undefined = 2) => ({
|
||||
payload_json: JSON.stringify({ photos, description: null, facts: [], v }),
|
||||
fetched_at: fetchedAt,
|
||||
});
|
||||
|
||||
@@ -543,6 +545,18 @@ describe('result cache', () => {
|
||||
expect(maps.fetchCommonsCandidates).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ENRICH-023c: discards an entry written by an older format version', async () => {
|
||||
// Otherwise a release that adds a field keeps serving last week's answers.
|
||||
const maps = mapsStub({ fetchCommonsCandidates: vi.fn(async () => [commonsCandidate()]) });
|
||||
mockDbGet.mockImplementation((sql: string) =>
|
||||
String(sql).includes('place_details_cache') ? cachedRow([], Date.now(), 1) : undefined,
|
||||
);
|
||||
|
||||
await make(maps, cacheStub()).enrich(1, REQ);
|
||||
|
||||
expect(maps.fetchCommonsCandidates).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ENRICH-024: ignores an unreadable cache row and rebuilds', async () => {
|
||||
const maps = mapsStub({ fetchCommonsCandidates: vi.fn(async () => [commonsCandidate()]) });
|
||||
mockDbGet.mockImplementation((sql: string) =>
|
||||
@@ -630,9 +644,10 @@ describe('collectFacts', () => {
|
||||
);
|
||||
|
||||
expect(facts).toEqual([
|
||||
// Hours come from the block shared with Google, so they lead.
|
||||
{ kind: 'openingHours', value: 'Mo-Sa 17:30+', url: null },
|
||||
// Semicolons and underscores are OSM syntax, not something to show a reader.
|
||||
{ kind: 'cuisine', value: 'regional, german', url: null },
|
||||
{ kind: 'openingHours', value: 'Mo-Sa 17:30+', url: null },
|
||||
{ kind: 'menu', value: null, url: 'https://example.org/menu' },
|
||||
{ kind: 'outdoorSeating', value: null, url: null },
|
||||
{ kind: 'wheelchair', value: 'limited', url: null },
|
||||
@@ -659,9 +674,20 @@ describe('collectFacts', () => {
|
||||
expect(facts.find((f) => f.kind === 'internetAccess')).toEqual({ kind: 'internetAccess', value: null, url: null });
|
||||
});
|
||||
|
||||
it('ENRICH-053: stays empty for a Google place and for no details at all', () => {
|
||||
it('ENRICH-053: takes the rating and hours from a Google place, but not its OSM-only tags', () => {
|
||||
expect(collectFacts(null)).toEqual([]);
|
||||
expect(collectFacts({ source: 'google', cuisine: 'italian' })).toEqual([]);
|
||||
// cuisine/outdoor_seating are OSM tagging and never appear on a Google blob.
|
||||
expect(collectFacts({ source: 'google', cuisine: 'italian', outdoor_seating: 'yes' })).toEqual([]);
|
||||
expect(
|
||||
collectFacts({ source: 'google', rating: 4.5, rating_count: 1234, opening_hours: ['Mo-Fr 09:00-18:00'] }),
|
||||
).toEqual([
|
||||
{ kind: 'rating', value: '4.5 (1234)', url: null },
|
||||
{ kind: 'openingHours', value: 'Mo-Fr 09:00-18:00', url: null },
|
||||
]);
|
||||
});
|
||||
|
||||
it('ENRICH-053b: omits the review count when there is none', () => {
|
||||
expect(collectFacts({ source: 'google', rating: 4 })).toEqual([{ kind: 'rating', value: '4', url: null }]);
|
||||
});
|
||||
|
||||
it('ENRICH-054: joins multi-day opening hours into one readable line', () => {
|
||||
|
||||
Reference in New Issue
Block a user