/* 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 unionTelemetry from '/imports/startup/server/unionTelemetry'; 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, telemetry: unionTelemetry }); 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(); } }); });