Added priv subsUnion

This commit is contained in:
vjrj 2018-03-17 00:38:09 +01:00
parent 5febb231be
commit a83e2de12f

View file

@ -26,59 +26,66 @@ Meteor.startup(() => {
return sub; return sub;
}; };
const process = () => { const process = (isPublic) => {
const group = new L.FeatureGroup(); const group = new L.FeatureGroup();
const result = calcUnion(Subscriptions.find().fetch(), group, addNoisy); const result = calcUnion(Subscriptions.find().fetch(), group, isPublic ? addNoisy : sub => sub);
const union = result[0]; const union = result[0];
const bounds = result[1]; const bounds = result[1];
const publicl = isPublic ? 'public' : 'private';
const Publicl = publicl.replace(/\b\w/g, l => l.toUpperCase());
if (typeof union === 'object') { if (typeof union === 'object') {
const unionSet = { const unionSet = {
$set: { $set: {
name: 'subs-public-union', name: `subs-${publicl}-union`,
value: JSON.stringify(union), value: JSON.stringify(union),
isPublic: true, isPublic,
description: 'Public subscriptions union', description: `${Publicl} subscriptions union`,
type: 'string' type: 'string'
} }
}; };
const boundsSet = { const boundsSet = {
$set: { $set: {
name: 'subs-public-union-bounds', name: `subs-${publicl}-union-bounds`,
value: JSON.stringify(bounds), value: JSON.stringify(bounds),
isPublic: true, isPublic,
description: 'Public subscriptions union bounds', description: `${Publicl} subscriptions union bounds`,
type: 'string' type: 'string'
} }
}; };
// FIXME, take care of object size: // FIXME, take care of object size:
// https://stackoverflow.com/questions/10827812/what-is-the-length-maximum-for-a-string-data-type-in-mongodb-used-with-ruby // https://stackoverflow.com/questions/10827812/what-is-the-length-maximum-for-a-string-data-type-in-mongodb-used-with-ruby
SiteSettings.upsert({ name: 'subs-public-union' }, unionSet, { multi: false }); SiteSettings.upsert({ name: `subs-${publicl}-union` }, unionSet, { multi: false });
SiteSettings.upsert({ name: 'subs-public-union-bounds' }, boundsSet, { multi: false }); SiteSettings.upsert({ name: `subs-${publicl}-union-bounds` }, boundsSet, { multi: false });
if (Meteor.isDevelopment) console.log('Subscription union calculated'); if (Meteor.isDevelopment) console.log(`${Publicl} subscription union calculated`);
} else { } else {
console.log('Subscription union failed!'); console.log('Subscription union failed!');
} }
}; };
// At startup // At startup
process(); process(true);
process(false);
Subscriptions.find({ createdAt: { $gt: new Date() } }).observe({ Subscriptions.find({ createdAt: { $gt: new Date() } }).observe({
added: function newSubAdded() { // doc) { added: function newSubAdded() { // doc) {
if (Meteor.isDevelopment) console.log('Subs added so recreate union'); if (Meteor.isDevelopment) console.log('Subs added so recreate union');
process(); process(true);
process(false);
} }
}); });
Subscriptions.find().observe({ Subscriptions.find().observe({
changed: function subsChanged() { // updatedDoc, oldDoc) { changed: function subsChanged() { // updatedDoc, oldDoc) {
if (Meteor.isDevelopment) console.log('Subs changed so recreate union'); if (Meteor.isDevelopment) console.log('Subs changed so recreate union');
process(); process(true);
process(false);
}, },
removed: function subsRemoved() { // oldDoc) { removed: function subsRemoved() { // oldDoc) {
if (Meteor.isDevelopment) console.log('Subs removed so recreate union'); if (Meteor.isDevelopment) console.log('Subs removed so recreate union');
process(); process(true);
process(false);
} }
}); });
}); });