Skip to content

armgit / TREK

Public Imported from GitHub
0

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.

place-enrichment: a community summary the request carried stays out of the shared cache

Maurice6945b53c105f
diff --git a/server/src/nest/place-enrichment/place-enrichment.service.ts b/server/src/nest/place-enrichment/place-enrichment.service.ts
index 60dcc6e4f..38a7c541e 100644
--- a/server/src/nest/place-enrichment/place-enrichment.service.ts
+++ b/server/src/nest/place-enrichment/place-enrichment.service.ts
@@ -454,15 +454,18 @@ export class PlaceEnrichmentService {
rating: collectRating(details) ?? collectRating(osmDetails),
};
// The cache is keyed by place and language, so a row written here is what
- // every user of the instance sees for a week. An OpenStreetMap summary and
- // a menu link are the two things read straight off the request's own
- // `details` that become a link on every screen, and when the request
- // carried those, the text and the link are the caller's word rather than
- // the map's: fine to answer them with, not to serve to everyone else. The
- // row simply is not written, and the next request computes its own answer.
- // A summary or a link the lookup here fetched itself is the map's and keeps.
+ // every user of the instance sees for a week. An OpenStreetMap or community
+ // summary and a menu link are the things read straight off the request's
+ // own `details` that end up on every screen, and when the request carried
+ // those, the text and the link are the caller's word rather than the
+ // map's: fine to answer them with, not to serve to everyone else. The row
+ // simply is not written, and the next request computes its own answer. A
+ // summary or a link the lookup here fetched itself is the map's and keeps.
const fromCaller =
- req.details != null && (description?.source === 'osm' || ownFacts.some((fact) => fact.url != null));
+ req.details != null &&
+ (description?.source === 'osm' ||
+ description?.source === 'community' ||
+ ownFacts.some((fact) => fact.url != null));
if (!fromCaller) await this.writeCache(placeId, lang, { ...result, cv: communityVersion(placeId, details) });
return result;
}
diff --git a/server/tests/unit/nest/place-enrichment.description.test.ts b/server/tests/unit/nest/place-enrichment.description.test.ts
index 890324eff..5315a678a 100644
--- a/server/tests/unit/nest/place-enrichment.description.test.ts
+++ b/server/tests/unit/nest/place-enrichment.description.test.ts
@@ -632,6 +632,18 @@ describe("the description on the place's own website", () => {
expect(mockUpsertEntry).toHaveBeenCalledTimes(1);
});
+ it('ENRICH-122: a community summary the request carried is answered, but not cached for everyone', async () => {
+ // The community credit is read off the details as well, so a request can
+ // claim it for any text; the sender sees it, the row is not written.
+ const out = await make(mapsStub()).enrich(1, {
+ ...OSM_REQ,
+ details: { source: 'openstreetmap', summary: 'Buchung nur über phish.example', summary_source: 'community' },
+ });
+
+ expect(out.description).toMatchObject({ source: 'community', text: 'Buchung nur über phish.example' });
+ expect(mockUpsertEntry).not.toHaveBeenCalled();
+ });
+
it('ENRICH-119: with the index switched off, no lookup leaves for the description', async () => {
// TREK_PLACES_ENABLED=false is a promise about egress, and a saved index
// place opened later is still an index place.