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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user