mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 14:36:31 +00:00
refactor(roadtrip, reservations): return await on transactional; document the single-flight promises
This commit is contained in:
@@ -779,7 +779,7 @@ export class ReservationsService {
|
||||
return { reservation, accommodationCreated, stayMirror };
|
||||
}
|
||||
|
||||
async updatePositions(tripId: string | number, positions: { id: number; day_plan_position?: number }[], dayId?: number | string | null): Promise<void> {
|
||||
async updatePositions(tripId: string | number, positions: { id: number; day_plan_position?: number }[], dayId?: number | string | null) {
|
||||
if (dayId) {
|
||||
// Per-day positions for multi-day reservations, scoped the way the legacy
|
||||
// branch below already scopes its update. The table carries no trip_id and
|
||||
|
||||
@@ -66,6 +66,8 @@ export class ChargingService {
|
||||
private loadTariffs(source: string): Promise<ChargingTariff[]> {
|
||||
const cached = this.tariffs.get(source);
|
||||
if (cached && cached.expires > Date.now()) return cached.value;
|
||||
// Memoised in-flight fetch, not a missing await: the promise itself is cached
|
||||
// so concurrent callers within the TTL share one request; the caller awaits it.
|
||||
const value = this.fetchTariffs(source);
|
||||
this.tariffs.set(source, { expires: Date.now() + 300000, value });
|
||||
return value;
|
||||
|
||||
@@ -33,6 +33,8 @@ export class RoadtripHazardsService {
|
||||
async read(): Promise<RoadtripHazards> {
|
||||
if (this.cached && Date.now() - Date.parse(this.cached.fetchedAt) < 600000) return this.cached;
|
||||
if (this.pending !== undefined) return this.pending;
|
||||
// Memoised in-flight load, not a missing await: concurrent readers join the
|
||||
// pending promise above, and this frame awaits it below.
|
||||
this.pending = this.load();
|
||||
try { this.cached = await this.pending; return this.cached; }
|
||||
finally { this.pending = undefined; }
|
||||
|
||||
@@ -104,7 +104,7 @@ export class RoadtripService {
|
||||
track?: { place_id: number; stray_km?: number | null } | null;
|
||||
},
|
||||
): Promise<RoadtripVia[]> {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
// Inside the same transaction as the chain it describes. A day that says it follows
|
||||
// a road whose vias never landed is worse than a day that says nothing.
|
||||
if (input.track === null) {
|
||||
@@ -222,7 +222,7 @@ export class RoadtripService {
|
||||
dayId: string | number,
|
||||
input: { vias: { id: number; after_order_index: number }[]; remove?: number[] },
|
||||
): Promise<RoadtripVia[]> {
|
||||
return this.uow.transactional(async () => {
|
||||
return await this.uow.transactional(async () => {
|
||||
// Read before writing: the OLD anchor is what says which of two merged
|
||||
// legs came first, and after the updates that information is gone.
|
||||
const before = new Map(
|
||||
|
||||
Reference in New Issue
Block a user