feat(subsUnion): incremental union merge for new subscriptions
All checks were successful
build-image / build (push) Successful in 13m24s
All checks were successful
build-image / build (push) Successful in 13m24s
A full recreate() over 7k+ subscriptions takes ~20 minutes even in a worker thread — fine for not blocking the site, but means a new zone takes ages to show up on the map. Since union only grows when adding a circle, a new subscription can just be merged into the union already stored (one turf.union call) instead of rebuilding the whole chain. changed/removed still trigger a full recreate() (union can't be "subtracted" from safely), and incrementalAdd falls back to a full recreate whenever the stored count isn't exactly one behind what's expected, rather than risk merging into stale state. Both paths now share one serialized queue (FIFO for adds, coalesced for recomputes) so they never race on the same stored union.
This commit is contained in:
parent
fbb746fba2
commit
110ad66e86
3 changed files with 111 additions and 52 deletions
|
|
@ -7,10 +7,11 @@ const WORKER_PATH = path.resolve(process.cwd(), 'assets/app/workers/unionWorker.
|
|||
* Circle-union of already-validated, already-decorated subscriptions, run in a
|
||||
* worker thread so the main event loop (DDP/HTTP) stays free regardless of
|
||||
* how long any single turf.union call takes. subs must be an array of plain
|
||||
* { location: { lat, lon }, distance } objects.
|
||||
* { location: { lat, lon }, distance } objects. If baseUnion is given, subs
|
||||
* are merged into it instead of a union computed from scratch.
|
||||
*/
|
||||
const calcUnionAsync = subs => new Promise((resolve, reject) => {
|
||||
const worker = new Worker(WORKER_PATH, { workerData: { subs } });
|
||||
const calcUnionAsync = (subs, baseUnion = null) => new Promise((resolve, reject) => {
|
||||
const worker = new Worker(WORKER_PATH, { workerData: { subs, baseUnion } });
|
||||
worker.once('message', (msg) => {
|
||||
worker.terminate();
|
||||
if (msg.error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue