fix(subsUnion): move geo-union math to a worker thread, not just yields
All checks were successful
build-image / build (push) Successful in 13m13s

The previous fix (yielding to the event loop between turf.union calls)
was not enough: once the merged polygon gets complex with thousands of
subscriptions, a single turf.union call can itself take seconds, and
yielding between iterations doesn't help when one iteration alone
blocks that long. Confirmed in staging: the site was still fully
unresponsive (Cloudflare 524, curl hanging 2+ minutes, healthcheck
failing) while a recompute ran.

Validation/decoration (addNoisy/noNoisy, cheap) stays on the main
thread; the actual circle+union chain now runs in a worker_thread
(private/workers/unionWorker.js, plain CommonJS so meteor build copies
it verbatim instead of compiling it) so the main event loop serving
DDP/HTTP is never blocked by it, regardless of how slow any single
turf call gets.
This commit is contained in:
vjrj 2026-07-30 07:48:17 +02:00
parent 3d52e2f709
commit fbb746fba2
3 changed files with 75 additions and 48 deletions

View file

@ -37,7 +37,20 @@ Meteor.startup(async () => {
const process = async (isPublic) => {
const subscribers = await Subscriptions.find().fetchAsync();
const union = await calcUnionAsync(subscribers, isPublic ? addNoisy : noNoisy);
const decorate = isPublic ? addNoisy : noNoisy;
const validSubs = subscribers.filter((osub) => {
const valid = osub.location && osub.location.lat && osub.location.lon && osub.distance;
if (!valid) console.info(`Wrong element to do union ${JSON.stringify(osub)}`);
return valid;
});
const decorated = validSubs.map(decorate);
let union = null;
try {
union = await calcUnionAsync(decorated);
} catch (e) {
console.error('subsUnion worker failed', e);
}
const bounds = union === null ? null : L.geoJSON(union).getBounds();
const publicl = isPublic ? 'public' : 'private';