Everything the union does lived inside a Meteor.startup callback with no exports:
the queue, the incremental fast path, the worker-failure handling. None of it was
reachable from a test, which is how three separate incidents shipped — a failed
worker stored as an empty union (50ca9cc), turf deps unresolvable from the worker
(3249362/570cb49) and a recompute that blocked the event loop and froze DDP
(b4e5511/fbb746f). subsUnionLogic.js now takes its collaborators as arguments and
subsUnion.js is only the wiring.
The FIXME at the old subsUnion.js:82 goes with it, because it lives inside the
extracted storeUnion: a union over 16 MiB is simply rejected by Mongo, so the map
would freeze at the last union that happened to fit, silently. unionSizeGuard.js
degrades the geometry instead — coordinate precision, then vertex decimation,
then holes, then the smallest polygons — until it fits, and reports what it did
so the setting document records it. The cap is 8 MiB rather than 16: the same
string is pushed to every browser over DDP.
addNoisy no longer mutates the document it is given, so the public pass cannot
leak its fuzzing into the private one.
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
/* eslint-disable import/no-absolute-path */
|
|
|
|
// Wiring only: what the union actually does lives in subsUnionLogic.js, where it
|
|
// can be tested without booting a server (see test/server/subsUnion.test.js).
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
import Subscriptions from '/imports/api/Subscriptions/Subscriptions';
|
|
import SiteSettings from '/imports/api/SiteSettings/SiteSettings';
|
|
import calcUnionAsync from '/imports/startup/server/calcUnionAsync';
|
|
import unionBounds from '/imports/startup/server/unionBounds';
|
|
import createSubsUnion from '/imports/startup/server/subsUnionLogic';
|
|
import { isMailServerMaster } from '/imports/startup/server/email';
|
|
|
|
Meteor.startup(async () => {
|
|
if (!isMailServerMaster) {
|
|
console.log('We only process subsUnion in master');
|
|
return;
|
|
}
|
|
|
|
const subsUnion = createSubsUnion({
|
|
calcUnion: calcUnionAsync,
|
|
SiteSettings,
|
|
Subscriptions,
|
|
boundsOf: unionBounds
|
|
});
|
|
|
|
if (await subsUnion.isUnionOutdated()) {
|
|
console.log('Subs union outdated');
|
|
subsUnion.scheduleRecreate();
|
|
} else {
|
|
console.log('Subs union up-to-date');
|
|
}
|
|
|
|
await Subscriptions.find({ createdAt: { $gt: new Date() } }).observeAsync({
|
|
added: function newSubAdded(doc) {
|
|
console.log('Subs added, merging into union incrementally');
|
|
subsUnion.enqueueAdd(doc);
|
|
}
|
|
});
|
|
|
|
await Subscriptions.find().observeAsync({
|
|
changed: function subsChanged() {
|
|
console.log('Subs changed so recreate union');
|
|
subsUnion.scheduleRecreate();
|
|
},
|
|
removed: function subsRemoved() {
|
|
console.log('Subs removed so recreate union');
|
|
subsUnion.scheduleRecreate();
|
|
}
|
|
});
|
|
});
|