@transportme/load-ptv-gtfs 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/loader/ShapeLoader.mjs +23 -5
- package/package.json +1 -1
|
@@ -32,9 +32,6 @@ export default class ShapeLoader {
|
|
|
32
32
|
|
|
33
33
|
async updateRoute(routeGTFSID, routePath) {
|
|
34
34
|
this.#routeCache[routeGTFSID].routePath = routePath
|
|
35
|
-
await this.#routes.updateDocument({
|
|
36
|
-
routeGTFSID
|
|
37
|
-
}, { $set: { routePath } })
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
generateDBShapeData(shape) {
|
|
@@ -79,14 +76,35 @@ export default class ShapeLoader {
|
|
|
79
76
|
*/
|
|
80
77
|
async loadShapes({ shapeIDMap }) {
|
|
81
78
|
await this.#shapeReader.open()
|
|
82
|
-
|
|
79
|
+
|
|
83
80
|
let shapesLoaded = 0
|
|
84
81
|
|
|
85
82
|
while (this.#shapeReader.available()) {
|
|
86
83
|
let shape = await this.#shapeReader.getNextEntity()
|
|
87
84
|
await this.loadShape(shape, shapeIDMap)
|
|
88
85
|
|
|
89
|
-
if (++shapesLoaded === 1000)
|
|
86
|
+
if (++shapesLoaded === 1000) {
|
|
87
|
+
await this.writeShapes()
|
|
88
|
+
shapeLength = 0
|
|
89
|
+
}
|
|
90
90
|
}
|
|
91
|
+
await this.writeShapes()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async writeShapes() {
|
|
95
|
+
let dirtyShapes = Object.keys(this.#routeCache)
|
|
96
|
+
if (!dirtyShapes.length) return
|
|
97
|
+
|
|
98
|
+
let bulkUpdate = dirtyShapes.map(routeGTFSID => ({
|
|
99
|
+
updateOne: {
|
|
100
|
+
filter: { routeGTFSID },
|
|
101
|
+
update: {
|
|
102
|
+
$set: { routePath: this.#routeCache[routeGTFSID].routePath }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}))
|
|
106
|
+
|
|
107
|
+
await this.#routes.bulkWrite(bulkUpdate)
|
|
108
|
+
this.#routeCache = {}
|
|
91
109
|
}
|
|
92
110
|
}
|