fix(tours): checklist entries within their contract, whole locks and a leaner reading

A lock flight chained into one group of more than 30 parts broke the
checklist's contract and made every decision about it fail; an entry now
names its nearest part and the first others, a portage lists at most 30
obstacles and a checklist at most 100 own entries. Reading along a line
takes in the parts of a lock the corridor cut off, so its data basis no
longer depends on how the route runs. A line or an area stands at the
middle of its extent, so adding a node leaves it in place, and an earlier
decision is judged by where the obstacle was, not by the route point of its
passage. The cache keeps its readings without their lines, for one data
version at a time, and the data version is read without the region
boundaries.
This commit is contained in:
Maurice
2026-10-17 02:07:22 +00:00
parent d46b6fb646
commit 2a4b71b3d9
12 changed files with 308 additions and 79 deletions
@@ -18,6 +18,22 @@ export interface PaddleFeatureRow {
max_lng: number;
}
/** The columns a stored object is read with. */
const FEATURE_COLUMNS = [
'region_id',
'osm_ref',
'kind',
'group_key',
'name',
'geometry',
'tags',
'tag_hash',
'min_lat',
'min_lng',
'max_lat',
'max_lng',
] as const;
/** A box in degrees, south to north and west to east. */
export interface Box {
south: number;
@@ -43,20 +59,22 @@ export class PaddleFeaturesRepository extends TrekRepository<PaddleFeatures> {
async findInBox(box: Box, limit: number): Promise<PaddleFeatureRow[]> {
return await this.db()
.selectFrom('paddle_features')
.select([
'region_id',
'osm_ref',
'kind',
'group_key',
'name',
'geometry',
'tags',
'tag_hash',
'min_lat',
'min_lng',
'max_lat',
'max_lng',
])
.select(FEATURE_COLUMNS)
.where('min_lat', '<=', box.north)
.where('max_lat', '>=', box.south)
.where('min_lng', '<=', box.east)
.where('max_lng', '>=', box.west)
.orderBy('id', 'asc')
.limit(limit)
.execute();
}
/** The parts of the given locks whose box reaches into `box`, at most `limit` of them, in a stable order. */
async findGroupParts(keys: readonly string[], box: Box, limit: number): Promise<PaddleFeatureRow[]> {
return await this.db()
.selectFrom('paddle_features')
.select(FEATURE_COLUMNS)
.where('group_key', 'in', [...keys])
.where('min_lat', '<=', box.north)
.where('max_lat', '>=', box.south)
.where('min_lng', '<=', box.east)
@@ -49,6 +49,11 @@ export class PaddleRegionsRepository extends TrekRepository<PaddleRegions> {
return await this.db().selectFrom('paddle_regions').select(COLUMNS).orderBy('name', 'asc').execute();
}
/** When each region was last read, by id: what the obstacle data's version is made of, without the boundaries. */
async readTimes(): Promise<Array<{ id: string; imported_at: string | null }>> {
return await this.db().selectFrom('paddle_regions').select(['id', 'imported_at']).orderBy('id', 'asc').execute();
}
async findById(id: string): Promise<PaddleRegionRow | undefined> {
return await this.db().selectFrom('paddle_regions').select(COLUMNS).where('id', '=', id).executeTakeFirst();
}