diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3262e35..2c17e81 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -14,6 +14,7 @@ "@mui/material": "5.x", "express": "^4.18.2", "leaflet": "^1.9.4", + "p-queue": "^8.0.1", "react": "18.x", "react-calendar": "^4.6.1", "react-date-picker": "^8.4.0", @@ -4447,6 +4448,11 @@ "node": ">= 0.6" } }, + "node_modules/eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" + }, "node_modules/events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", @@ -6518,6 +6524,32 @@ "node": ">=6" } }, + "node_modules/p-queue": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-8.0.1.tgz", + "integrity": "sha512-NXzu9aQJTAzbBqOt2hwsR63ea7yvxJc0PwN/zobNAudYfb1B7R08SzB4TsLeSbUCuG467NhnoT0oO6w1qRO+BA==", + "dependencies": { + "eventemitter3": "^5.0.1", + "p-timeout": "^6.1.2" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-timeout": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-6.1.2.tgz", + "integrity": "sha512-UbD77BuZ9Bc9aABo74gfXhNvzC9Tx7SxtHSh1fxvx3jTLLYvmVhiQZZrJzqqU0jKbN32kb5VOKiLEQI/3bIjgQ==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index c295608..79e3ae5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -46,6 +46,7 @@ "@mui/material": "5.x", "express": "^4.18.2", "leaflet": "^1.9.4", + "p-queue": "^8.0.1", "react": "18.x", "react-calendar": "^4.6.1", "react-date-picker": "^8.4.0", diff --git a/frontend/src/spatialData.js b/frontend/src/spatialData.js index 6f45eec..93d1650 100644 --- a/frontend/src/spatialData.js +++ b/frontend/src/spatialData.js @@ -5,12 +5,14 @@ import { Days } from './days.js' import { HolidayOption } from './holidayOption.js' import { TravelTimeQuery } from './travelTimeQuery.js' import { domain } from './domain.js' +import PQueue from 'p-queue' // instantiated once, this is the data store for all spatial and temporal data export class SpatialData { #factors = [] #queries = new Map() // store/cache for travelTimeQueries, letting them remember their results if any #knownHolidays = [] + #queue = new PQueue({concurrency: 3}) constructor(){ this.#factors.push(new Days(this)) this.#factors.push(new HolidayOption(this,true)) @@ -116,10 +118,10 @@ export class SpatialData { return [...this.#queries.values()].sort((a,b)=> a.URI < b.URI ? -1 : 1) } fetchAllResults(){ - return Promise.all( + return this.#queue.addAll( this.travelTimeQueries .filter( TTQ => ! TTQ.hasData ) - .map( TTQ => TTQ.fetchData() ) + .map( TTQ => () => TTQ.fetchData() ) ) } }