perf(api): load the discovery set once per location request

getCurrentLocation was calling isTravelAllowed per connection, re-querying
the character's discovered locations once per gated exit. Extract the
gating rule into a pure, synchronous WorldDiscoveryService.isRouteOpen so
the map filter can load the discovery set once and filter in memory, while
isTravelAllowed (TravelService's entry point) keeps its exact signature and
behaviour by delegating to the same rule. Also pins that discoversLocationKey
never reaches the client payload.
This commit is contained in:
Bastian Wagner
2026-08-23 11:28:42 +02:00
parent 37d025f401
commit ac7750902a
3 changed files with 57 additions and 19 deletions

View File

@@ -87,15 +87,16 @@ export class WorldService {
? await this.getEncounterPool(location.id)
: [];
const visibleConnections: LocationConnection[] = [];
for (const connection of connections) {
if (
// Loaded once per request rather than per connection: `isRouteOpen` is
// synchronous, so a location with several gated exits costs one query
// here instead of one per gated connection.
const discoveredLocationIds =
await this.worldDiscovery.getDiscoveredLocationIds(characterId);
const visibleConnections = connections.filter(
(connection) =>
connection.enabled &&
(await this.worldDiscovery.isTravelAllowed(characterId, connection))
) {
visibleConnections.push(connection);
}
}
this.worldDiscovery.isRouteOpen(discoveredLocationIds, connection),
);
return {
id: location.id,