@resolveio/server-lib 9.7.7 → 9.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/managers/subscription.manager.d.ts +2 -3
- package/managers/subscription.manager.js +330 -320
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +21 -12
- package/methods/accounts.js.map +1 -1
- package/package.json +1 -1
- package/server-app.js +4 -2
- package/server-app.js.map +1 -1
|
@@ -65,10 +65,20 @@ var common_1 = require("../util/common");
|
|
|
65
65
|
var moment = require("moment");
|
|
66
66
|
var NodeCache = require("node-cache");
|
|
67
67
|
var v8 = require('v8');
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
// interface CurrentPerformanceMonitor {
|
|
69
|
+
// _id: number;
|
|
70
|
+
// function: string;
|
|
71
|
+
// publication: string;
|
|
72
|
+
// subscriptionData: any[];
|
|
73
|
+
// date_start: Date;
|
|
74
|
+
// date_end: Date;
|
|
75
|
+
// duration: number;
|
|
76
|
+
// result: string;
|
|
77
|
+
// }
|
|
71
78
|
var SubscriptionManager = /** @class */ (function () {
|
|
79
|
+
// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];
|
|
80
|
+
// private idPerformance: number = 0;
|
|
81
|
+
// private performanceThread;
|
|
72
82
|
function SubscriptionManager(mainServer, wss, serverConfig) {
|
|
73
83
|
var _this = this;
|
|
74
84
|
this._publications = {};
|
|
@@ -81,26 +91,24 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
81
91
|
this._cacheId = 1;
|
|
82
92
|
this._heapStats = v8.getHeapStatistics();
|
|
83
93
|
this._heapLimit = 0;
|
|
84
|
-
this.currentPerfomanceMonitor = [];
|
|
85
|
-
this.idPerformance = 0;
|
|
86
94
|
this._mainServer = mainServer;
|
|
87
95
|
this._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 0 });
|
|
88
96
|
this._heapLimit = this._heapStats.heap_size_limit / 4;
|
|
89
|
-
setTimeout(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}, 5000);
|
|
99
|
-
setInterval(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}, 10000);
|
|
97
|
+
// setTimeout(() => {
|
|
98
|
+
// console.log('Setting up performance thread');
|
|
99
|
+
// this.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));
|
|
100
|
+
// this.performanceThread.on('exit', code => {
|
|
101
|
+
// console.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);
|
|
102
|
+
// });
|
|
103
|
+
// this.performanceThread.on('error', code => {
|
|
104
|
+
// console.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);
|
|
105
|
+
// });
|
|
106
|
+
// }, 5000);
|
|
107
|
+
// setInterval(() => {
|
|
108
|
+
// console.log('Post thread msg');
|
|
109
|
+
// this.performanceThread.postMessage(this.currentPerfomanceMonitor);
|
|
110
|
+
// this.currentPerfomanceMonitor = [];
|
|
111
|
+
// }, 10000);
|
|
104
112
|
this.serverConfig = serverConfig;
|
|
105
113
|
this._wss = wss;
|
|
106
114
|
// Publications
|
|
@@ -120,12 +128,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
120
128
|
report_builder_dashboard_builders_1.loadReportBuilderDashboardBuilderPublications(this);
|
|
121
129
|
this.tailOpLog();
|
|
122
130
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
123
|
-
var
|
|
131
|
+
var _loop_1, this_1, i, queueArr, i, mongoQueue, j, client, ws;
|
|
124
132
|
var _this = this;
|
|
125
133
|
return __generator(this, function (_a) {
|
|
126
134
|
if (!this._runningQueue) {
|
|
127
135
|
if (this._sendQueue.length) {
|
|
128
|
-
startDate = new Date();
|
|
136
|
+
// let startDate = new Date();
|
|
129
137
|
this._runningQueue = true;
|
|
130
138
|
_loop_1 = function (i) {
|
|
131
139
|
var ws = this_1._mainServer.getWS(this_1._sendQueue[i].id_ws);
|
|
@@ -149,17 +157,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
149
157
|
_loop_1(i);
|
|
150
158
|
}
|
|
151
159
|
this._runningQueue = false;
|
|
152
|
-
endDate = new Date();
|
|
153
|
-
this.currentPerfomanceMonitor.push({
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
160
|
+
// let endDate = new Date();
|
|
161
|
+
// this.currentPerfomanceMonitor.push({
|
|
162
|
+
// _id: this.idPerformance++,
|
|
163
|
+
// function: 'sendInterval',
|
|
164
|
+
// publication: '',
|
|
165
|
+
// subscriptionData: [],
|
|
166
|
+
// date_start: startDate,
|
|
167
|
+
// date_end: endDate,
|
|
168
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
169
|
+
// result: 'Done'
|
|
170
|
+
// });
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
|
|
@@ -167,7 +175,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
167
175
|
queueArr.forEach(function (entry) {
|
|
168
176
|
entry.running = true;
|
|
169
177
|
});
|
|
170
|
-
startDate = new Date();
|
|
178
|
+
// let startDate = new Date();
|
|
171
179
|
for (i = queueArr.length - 1; i >= 0; i--) {
|
|
172
180
|
mongoQueue = queueArr[i];
|
|
173
181
|
if (this._publications[mongoQueue.subscription.publication].ws_specific) {
|
|
@@ -190,17 +198,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
190
198
|
this._mongoQueue.splice(this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
191
199
|
}
|
|
192
200
|
}
|
|
193
|
-
endDate = new Date();
|
|
194
|
-
this.currentPerfomanceMonitor.push({
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
201
|
+
// let endDate = new Date();
|
|
202
|
+
// this.currentPerfomanceMonitor.push({
|
|
203
|
+
// _id: this.idPerformance++,
|
|
204
|
+
// function: 'mongoQueue',
|
|
205
|
+
// publication: '',
|
|
206
|
+
// subscriptionData: [],
|
|
207
|
+
// date_start: startDate,
|
|
208
|
+
// date_end: endDate,
|
|
209
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
210
|
+
// result: 'Done'
|
|
211
|
+
// });
|
|
204
212
|
}
|
|
205
213
|
return [2 /*return*/];
|
|
206
214
|
});
|
|
@@ -217,7 +225,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
217
225
|
userCopy = common_1.deepCopy(this._loggedInUsers);
|
|
218
226
|
_loop_2 = function (i) {
|
|
219
227
|
var loggedInUser = userCopy[i];
|
|
220
|
-
if (!loggedInUser.date || moment().diff(moment(loggedInUser.date), 'seconds') >=
|
|
228
|
+
if (!loggedInUser.date || moment().diff(moment(loggedInUser.date), 'seconds') >= 90) {
|
|
221
229
|
if (this_2._mainServer.getWS(loggedInUser.id_ws)) {
|
|
222
230
|
this_2.unsubscribeAll(this_2._mainServer.getWS(loggedInUser.id_ws));
|
|
223
231
|
}
|
|
@@ -260,56 +268,59 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
260
268
|
}); }, 30000);
|
|
261
269
|
}
|
|
262
270
|
SubscriptionManager.prototype.addToQueue = function (mongoQueue) {
|
|
263
|
-
|
|
271
|
+
// let startDate = new Date();
|
|
264
272
|
var _mongoQueue = this._mongoQueue.filter(function (a) { return a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); })[0];
|
|
265
273
|
if (_mongoQueue) {
|
|
266
274
|
if (_mongoQueue.running) {
|
|
267
275
|
_mongoQueue.run_again = true;
|
|
268
|
-
|
|
269
|
-
this.currentPerfomanceMonitor.push({
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
else {
|
|
281
|
-
var endDate = new Date();
|
|
282
|
-
this.currentPerfomanceMonitor.push({
|
|
283
|
-
_id: this.idPerformance++,
|
|
284
|
-
function: 'addToQueue',
|
|
285
|
-
publication: mongoQueue.subscription.publication,
|
|
286
|
-
subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
287
|
-
date_start: startDate,
|
|
288
|
-
date_end: endDate,
|
|
289
|
-
duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
290
|
-
result: 'Not Running Yet'
|
|
291
|
-
});
|
|
276
|
+
// let endDate = new Date();
|
|
277
|
+
// this.currentPerfomanceMonitor.push({
|
|
278
|
+
// _id: this.idPerformance++,
|
|
279
|
+
// function: 'addToQueue',
|
|
280
|
+
// publication: mongoQueue.subscription.publication,
|
|
281
|
+
// // subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
282
|
+
// subscriptionData: [],
|
|
283
|
+
// date_start: startDate,
|
|
284
|
+
// date_end: endDate,
|
|
285
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
286
|
+
// result: 'Run Again'
|
|
287
|
+
// });
|
|
292
288
|
}
|
|
289
|
+
// else {
|
|
290
|
+
// let endDate = new Date();
|
|
291
|
+
// this.currentPerfomanceMonitor.push({
|
|
292
|
+
// _id: this.idPerformance++,
|
|
293
|
+
// function: 'addToQueue',
|
|
294
|
+
// publication: mongoQueue.subscription.publication,
|
|
295
|
+
// // subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
296
|
+
// subscriptionData: [],
|
|
297
|
+
// date_start: startDate,
|
|
298
|
+
// date_end: endDate,
|
|
299
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
300
|
+
// result: 'Not Running Yet'
|
|
301
|
+
// });
|
|
302
|
+
// }
|
|
293
303
|
}
|
|
294
304
|
else {
|
|
295
305
|
mongoQueue._id = this._mongoQueueId;
|
|
296
306
|
this._mongoQueueId += 1;
|
|
297
307
|
this._mongoQueue.splice(0, 0, mongoQueue);
|
|
298
|
-
|
|
299
|
-
this.currentPerfomanceMonitor.push({
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
// let endDate = new Date();
|
|
309
|
+
// this.currentPerfomanceMonitor.push({
|
|
310
|
+
// _id: this.idPerformance++,
|
|
311
|
+
// function: 'addToQueue',
|
|
312
|
+
// publication: mongoQueue.subscription.publication,
|
|
313
|
+
// // subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
314
|
+
// subscriptionData: [],
|
|
315
|
+
// date_start: startDate,
|
|
316
|
+
// date_end: endDate,
|
|
317
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
318
|
+
// result: 'Add to Queue'
|
|
319
|
+
// });
|
|
309
320
|
}
|
|
310
321
|
};
|
|
311
322
|
SubscriptionManager.prototype.invalidatePubsCache = function (collection, type) {
|
|
312
|
-
|
|
323
|
+
// let startDate = new Date();
|
|
313
324
|
var collSubs = this._subscriptions.filter(function (a) { return a.collections.includes(collection); });
|
|
314
325
|
for (var i = collSubs.length - 1; i >= 0; i--) {
|
|
315
326
|
var sub = collSubs[i];
|
|
@@ -327,17 +338,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
327
338
|
});
|
|
328
339
|
}
|
|
329
340
|
index_1.ResolveIOServer.getMongoManager().invalidateQueryCache(collection);
|
|
330
|
-
|
|
331
|
-
this.currentPerfomanceMonitor.push({
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
});
|
|
341
|
+
// let endDate = new Date();
|
|
342
|
+
// this.currentPerfomanceMonitor.push({
|
|
343
|
+
// _id: this.idPerformance++,
|
|
344
|
+
// function: 'invalidatePubsCache',
|
|
345
|
+
// publication: collection,
|
|
346
|
+
// subscriptionData: [],
|
|
347
|
+
// date_start: startDate,
|
|
348
|
+
// date_end: endDate,
|
|
349
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
350
|
+
// result: 'Done'
|
|
351
|
+
// });
|
|
341
352
|
};
|
|
342
353
|
// Add all files to publications private object
|
|
343
354
|
SubscriptionManager.prototype.publications = function (method) {
|
|
@@ -345,21 +356,20 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
345
356
|
};
|
|
346
357
|
SubscriptionManager.prototype.loggedInLatency = function (ws) {
|
|
347
358
|
return __awaiter(this, void 0, void 0, function () {
|
|
348
|
-
var
|
|
359
|
+
var loggedInUser;
|
|
349
360
|
var _this = this;
|
|
350
361
|
return __generator(this, function (_a) {
|
|
351
|
-
date = new Date();
|
|
352
362
|
loggedInUser = this._loggedInUsers.filter(function (a) { return a.id_ws === ws['id_socket']; })[0];
|
|
353
363
|
if (loggedInUser) {
|
|
354
|
-
loggedInUser.date =
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
364
|
+
loggedInUser.date = new Date();
|
|
365
|
+
logged_in_users_collection_1.LoggedInUsers.findOneAndUpdate({ id_ws: ws['id_socket'] }, { $set: { latency: ws['latency'], date: loggedInUser.date } }).then(function (res) {
|
|
366
|
+
if (!res) {
|
|
367
|
+
_this.unsubscribeAll(ws);
|
|
368
|
+
}
|
|
369
|
+
}, function () {
|
|
358
370
|
_this.unsubscribeAll(ws);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
_this.unsubscribeAll(ws);
|
|
362
|
-
});
|
|
371
|
+
});
|
|
372
|
+
}
|
|
363
373
|
return [2 /*return*/];
|
|
364
374
|
});
|
|
365
375
|
});
|
|
@@ -371,127 +381,147 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
371
381
|
subscriptionData[_i - 4] = arguments[_i];
|
|
372
382
|
}
|
|
373
383
|
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
-
var
|
|
384
|
+
var pub, valObj, valKeys, rootKeys, i, sub_1, newLoggedInUser;
|
|
375
385
|
return __generator(this, function (_a) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
384
|
-
if (!pub.check) {
|
|
385
|
-
console.error(new Date(), 'No Check Function For Pub ' + publication);
|
|
386
|
-
return [2 /*return*/];
|
|
387
|
-
}
|
|
388
|
-
else if (!pub.check._schema) {
|
|
389
|
-
console.error(new Date(), 'No Check Schema For Pub ' + publication);
|
|
386
|
+
switch (_a.label) {
|
|
387
|
+
case 0:
|
|
388
|
+
pub = this._publications[publication];
|
|
389
|
+
if (!pub) {
|
|
390
|
+
console.error(new Date(), 'No Publication: ' + publication);
|
|
390
391
|
return [2 /*return*/];
|
|
391
392
|
}
|
|
392
393
|
else {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
for (i = 0; i < subscriptionData.length; i++) {
|
|
397
|
-
valObj[rootKeys[i]] = subscriptionData[i];
|
|
398
|
-
}
|
|
399
|
-
try {
|
|
400
|
-
pub.check.validate(valObj);
|
|
401
|
-
}
|
|
402
|
-
catch (errors) {
|
|
403
|
-
if (errors) {
|
|
404
|
-
console.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);
|
|
394
|
+
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
395
|
+
if (!pub.check) {
|
|
396
|
+
console.error(new Date(), 'No Check Function For Pub ' + publication);
|
|
405
397
|
return [2 /*return*/];
|
|
406
398
|
}
|
|
399
|
+
else if (!pub.check._schema) {
|
|
400
|
+
console.error(new Date(), 'No Check Schema For Pub ' + publication);
|
|
401
|
+
return [2 /*return*/];
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
valObj = {};
|
|
405
|
+
valKeys = Object.keys(pub.check._schema);
|
|
406
|
+
rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
407
|
+
for (i = 0; i < subscriptionData.length; i++) {
|
|
408
|
+
valObj[rootKeys[i]] = subscriptionData[i];
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
pub.check.validate(valObj);
|
|
412
|
+
}
|
|
413
|
+
catch (errors) {
|
|
414
|
+
if (errors) {
|
|
415
|
+
console.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);
|
|
416
|
+
return [2 /*return*/];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
422
|
+
// If sub found (another user watching same data), add client to same sub
|
|
423
|
+
if (sub_1) {
|
|
424
|
+
if (!sub_1.clients.some(function (a) { return a.id_socket === ws['id_socket'] && a.messageId === messageId; })) {
|
|
425
|
+
sub_1.clients.push({
|
|
426
|
+
id_user: ws['id_user'],
|
|
427
|
+
messageId: messageId,
|
|
428
|
+
id_socket: ws['id_socket']
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// If sub not found, create new sub
|
|
433
|
+
else {
|
|
434
|
+
this._subscriptions.push({
|
|
435
|
+
publication: publication,
|
|
436
|
+
subscriptionData: subscriptionData,
|
|
437
|
+
collections: this.getPublicationCollections(publication),
|
|
438
|
+
clients: [{
|
|
439
|
+
id_user: ws['id_user'],
|
|
440
|
+
messageId: messageId,
|
|
441
|
+
id_socket: ws['id_socket']
|
|
442
|
+
}],
|
|
443
|
+
cacheId: 0
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
if (!sub_1) {
|
|
447
|
+
sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
448
|
+
}
|
|
449
|
+
if (!sub_1.cacheId && !this._mongoQueue.some(function (a) { return a.subscription.publication === sub_1.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub_1.subscriptionData); })) {
|
|
450
|
+
this.addToQueue({
|
|
451
|
+
_id: 0,
|
|
452
|
+
type: 'newSub',
|
|
453
|
+
collection: '',
|
|
454
|
+
subscription: sub_1,
|
|
455
|
+
running: false,
|
|
456
|
+
run_again: false
|
|
457
|
+
});
|
|
458
|
+
// let endDate = new Date();
|
|
459
|
+
// this.currentPerfomanceMonitor.push({
|
|
460
|
+
// _id: this.idPerformance++,
|
|
461
|
+
// function: 'subscribe',
|
|
462
|
+
// publication: publication,
|
|
463
|
+
// // subscriptionData: subscriptionData,
|
|
464
|
+
// subscriptionData: [],
|
|
465
|
+
// date_start: startDate,
|
|
466
|
+
// date_end: endDate,
|
|
467
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
468
|
+
// result: 'Add to Queue'
|
|
469
|
+
// });
|
|
470
|
+
}
|
|
471
|
+
else if (sub_1.cacheId) {
|
|
472
|
+
this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
|
|
473
|
+
// let endDate = new Date();
|
|
474
|
+
// this.currentPerfomanceMonitor.push({
|
|
475
|
+
// _id: this.idPerformance++,
|
|
476
|
+
// function: 'subscribe',
|
|
477
|
+
// publication: publication,
|
|
478
|
+
// // subscriptionData: subscriptionData,
|
|
479
|
+
// subscriptionData: [],
|
|
480
|
+
// date_start: startDate,
|
|
481
|
+
// date_end: endDate,
|
|
482
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
483
|
+
// result: 'Send Pub Data Once'
|
|
484
|
+
// });
|
|
407
485
|
}
|
|
408
486
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
487
|
+
if (!(publication === 'appversion')) return [3 /*break*/, 2];
|
|
488
|
+
return [4 /*yield*/, this.ensureLoggedInUser(ws['id_socket'])];
|
|
489
|
+
case 1:
|
|
490
|
+
newLoggedInUser = _a.sent();
|
|
491
|
+
this._loggedInUsers.push(newLoggedInUser);
|
|
492
|
+
if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
|
|
493
|
+
this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'supportCreateBillingUser', {
|
|
415
494
|
id_user: ws['id_user'],
|
|
416
|
-
|
|
417
|
-
|
|
495
|
+
user: ws['user'],
|
|
496
|
+
date: new Date(),
|
|
497
|
+
client: index_1.ResolveIOServer.getClientName()
|
|
418
498
|
});
|
|
419
499
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
else {
|
|
423
|
-
this._subscriptions.push({
|
|
424
|
-
publication: publication,
|
|
425
|
-
subscriptionData: subscriptionData,
|
|
426
|
-
collections: this.getPublicationCollections(publication),
|
|
427
|
-
clients: [{
|
|
428
|
-
id_user: ws['id_user'],
|
|
429
|
-
messageId: messageId,
|
|
430
|
-
id_socket: ws['id_socket']
|
|
431
|
-
}],
|
|
432
|
-
cacheId: 0
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
if (!sub_1) {
|
|
436
|
-
sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
437
|
-
}
|
|
438
|
-
if (!sub_1.cacheId && !this._mongoQueue.some(function (a) { return a.subscription.publication === sub_1.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub_1.subscriptionData); })) {
|
|
439
|
-
this.addToQueue({
|
|
440
|
-
_id: 0,
|
|
441
|
-
type: 'newSub',
|
|
442
|
-
collection: '',
|
|
443
|
-
subscription: sub_1,
|
|
444
|
-
running: false,
|
|
445
|
-
run_again: false
|
|
446
|
-
});
|
|
447
|
-
endDate = new Date();
|
|
448
|
-
this.currentPerfomanceMonitor.push({
|
|
449
|
-
_id: this.idPerformance++,
|
|
450
|
-
function: 'subscribe',
|
|
451
|
-
publication: publication,
|
|
452
|
-
subscriptionData: subscriptionData,
|
|
453
|
-
date_start: startDate,
|
|
454
|
-
date_end: endDate,
|
|
455
|
-
duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
456
|
-
result: 'Add to Queue'
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
else if (sub_1.cacheId) {
|
|
460
|
-
this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
|
|
461
|
-
endDate = new Date();
|
|
462
|
-
this.currentPerfomanceMonitor.push({
|
|
463
|
-
_id: this.idPerformance++,
|
|
464
|
-
function: 'subscribe',
|
|
465
|
-
publication: publication,
|
|
466
|
-
subscriptionData: subscriptionData,
|
|
467
|
-
date_start: startDate,
|
|
468
|
-
date_end: endDate,
|
|
469
|
-
duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
470
|
-
result: 'Send Pub Data Once'
|
|
471
|
-
});
|
|
472
|
-
}
|
|
500
|
+
_a.label = 2;
|
|
501
|
+
case 2: return [2 /*return*/];
|
|
473
502
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
SubscriptionManager.prototype.ensureLoggedInUser = function (id_ws) {
|
|
507
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
508
|
+
var ws;
|
|
509
|
+
return __generator(this, function (_a) {
|
|
510
|
+
switch (_a.label) {
|
|
511
|
+
case 0:
|
|
512
|
+
ws = this._mainServer.getWS(id_ws);
|
|
513
|
+
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findOneAndUpdate({ id_ws: ws['id_socket'] }, {
|
|
514
|
+
$setOnInsert: {
|
|
515
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
516
|
+
__v: 0,
|
|
517
|
+
date: new Date(),
|
|
518
|
+
id_user: ws['id_user'],
|
|
519
|
+
user: ws['user'],
|
|
520
|
+
id_ws: ws['id_socket']
|
|
521
|
+
}
|
|
522
|
+
}, { upsert: true })];
|
|
523
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
493
524
|
}
|
|
494
|
-
return [2 /*return*/];
|
|
495
525
|
});
|
|
496
526
|
});
|
|
497
527
|
};
|
|
@@ -502,9 +532,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
502
532
|
subscriptionData[_i - 4] = arguments[_i];
|
|
503
533
|
}
|
|
504
534
|
return __awaiter(this, void 0, void 0, function () {
|
|
505
|
-
var
|
|
535
|
+
var sub, i;
|
|
506
536
|
return __generator(this, function (_a) {
|
|
507
|
-
startDate = new Date();
|
|
537
|
+
// let startDate = new Date();
|
|
508
538
|
// console.log('Before');
|
|
509
539
|
// console.dir(this._subscriptions.map(a => a.publication));
|
|
510
540
|
if (!this._publications[publication]) {
|
|
@@ -521,17 +551,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
521
551
|
}
|
|
522
552
|
}
|
|
523
553
|
}
|
|
524
|
-
endDate = new Date();
|
|
525
|
-
this.currentPerfomanceMonitor.push({
|
|
526
|
-
_id: this.idPerformance++,
|
|
527
|
-
function: 'unsubscribe',
|
|
528
|
-
publication: publication,
|
|
529
|
-
subscriptionData: subscriptionData,
|
|
530
|
-
date_start: startDate,
|
|
531
|
-
date_end: endDate,
|
|
532
|
-
duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
533
|
-
result: 'Done'
|
|
534
|
-
});
|
|
535
554
|
return [2 /*return*/];
|
|
536
555
|
});
|
|
537
556
|
});
|
|
@@ -539,11 +558,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
539
558
|
// Unsubscribe from publication
|
|
540
559
|
SubscriptionManager.prototype.unsubscribeAll = function (ws) {
|
|
541
560
|
return __awaiter(this, void 0, void 0, function () {
|
|
542
|
-
var
|
|
561
|
+
var loggedInUser, userSubs, i, sub, j;
|
|
543
562
|
return __generator(this, function (_a) {
|
|
544
563
|
switch (_a.label) {
|
|
545
564
|
case 0:
|
|
546
|
-
startDate = new Date();
|
|
547
565
|
if (!ws) return [3 /*break*/, 2];
|
|
548
566
|
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findOne({ id_ws: ws['id_socket'] })];
|
|
549
567
|
case 1:
|
|
@@ -564,17 +582,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
564
582
|
}
|
|
565
583
|
}
|
|
566
584
|
ws.terminate();
|
|
567
|
-
endDate = new Date();
|
|
568
|
-
this.currentPerfomanceMonitor.push({
|
|
569
|
-
_id: this.idPerformance++,
|
|
570
|
-
function: 'unsubscribeAll',
|
|
571
|
-
publication: '',
|
|
572
|
-
subscriptionData: [ws['id_socket']],
|
|
573
|
-
date_start: startDate,
|
|
574
|
-
date_end: endDate,
|
|
575
|
-
duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
576
|
-
result: 'Done'
|
|
577
|
-
});
|
|
578
585
|
_a.label = 2;
|
|
579
586
|
case 2: return [2 /*return*/];
|
|
580
587
|
}
|
|
@@ -590,7 +597,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
590
597
|
var _this = this;
|
|
591
598
|
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
592
599
|
this._oplog.on('change', function (doc) {
|
|
593
|
-
|
|
600
|
+
// let startDate = new Date();
|
|
594
601
|
if (doc.ns) {
|
|
595
602
|
var collection = doc.ns.coll;
|
|
596
603
|
// console.log(new Date(), 'Op log doc', doc.operationType, collection);
|
|
@@ -608,17 +615,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
608
615
|
if (collection !== 'method-responses') {
|
|
609
616
|
_this.invalidatePubsCache(collection, 'insert');
|
|
610
617
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
});
|
|
618
|
+
// let endDate = new Date();
|
|
619
|
+
// this.currentPerfomanceMonitor.push({
|
|
620
|
+
// _id: this.idPerformance++,
|
|
621
|
+
// function: 'oplog',
|
|
622
|
+
// publication: collection,
|
|
623
|
+
// subscriptionData: [],
|
|
624
|
+
// date_start: startDate,
|
|
625
|
+
// date_end: endDate,
|
|
626
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
627
|
+
// result: 'Insert'
|
|
628
|
+
// });
|
|
622
629
|
}
|
|
623
630
|
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
624
631
|
if (collection === 'cron-jobs') {
|
|
@@ -627,17 +634,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
627
634
|
if (collection !== 'method-responses') {
|
|
628
635
|
_this.invalidatePubsCache(collection, 'update');
|
|
629
636
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
});
|
|
637
|
+
// let endDate = new Date();
|
|
638
|
+
// this.currentPerfomanceMonitor.push({
|
|
639
|
+
// _id: this.idPerformance++,
|
|
640
|
+
// function: 'oplog',
|
|
641
|
+
// publication: collection,
|
|
642
|
+
// subscriptionData: [],
|
|
643
|
+
// date_start: startDate,
|
|
644
|
+
// date_end: endDate,
|
|
645
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
646
|
+
// result: 'Update'
|
|
647
|
+
// });
|
|
641
648
|
}
|
|
642
649
|
else if (doc.operationType === 'delete') {
|
|
643
650
|
if (collection === 'cron-jobs') {
|
|
@@ -646,17 +653,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
646
653
|
if (collection !== 'method-responses') {
|
|
647
654
|
_this.invalidatePubsCache(collection, 'delete');
|
|
648
655
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
});
|
|
656
|
+
// let endDate = new Date();
|
|
657
|
+
// this.currentPerfomanceMonitor.push({
|
|
658
|
+
// _id: this.idPerformance++,
|
|
659
|
+
// function: 'oplog',
|
|
660
|
+
// publication: collection,
|
|
661
|
+
// subscriptionData: [],
|
|
662
|
+
// date_start: startDate,
|
|
663
|
+
// date_end: endDate,
|
|
664
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
665
|
+
// result: 'Delete'
|
|
666
|
+
// });
|
|
660
667
|
}
|
|
661
668
|
}
|
|
662
669
|
}
|
|
@@ -674,11 +681,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
674
681
|
SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
|
|
675
682
|
var _this = this;
|
|
676
683
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
677
|
-
var
|
|
684
|
+
var cacheData, serverRes;
|
|
678
685
|
var _a;
|
|
679
686
|
var _this = this;
|
|
680
687
|
return __generator(this, function (_b) {
|
|
681
|
-
startDate = new Date();
|
|
688
|
+
// let startDate = new Date();
|
|
682
689
|
if (!this._publications[subscription.publication].ws_specific) { // Same pub for all users
|
|
683
690
|
if (subscription.cacheId) {
|
|
684
691
|
cacheData = null;
|
|
@@ -714,17 +721,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
714
721
|
run_again: false
|
|
715
722
|
});
|
|
716
723
|
}
|
|
717
|
-
endDate = new Date();
|
|
718
|
-
this.currentPerfomanceMonitor.push({
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
724
|
+
// let endDate = new Date();
|
|
725
|
+
// this.currentPerfomanceMonitor.push({
|
|
726
|
+
// _id: this.idPerformance++,
|
|
727
|
+
// function: 'sendPubDataOnce',
|
|
728
|
+
// publication: subscription.publication,
|
|
729
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
730
|
+
// subscriptionData: [],
|
|
731
|
+
// date_start: startDate,
|
|
732
|
+
// date_end: endDate,
|
|
733
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
734
|
+
// result: 'Send cache'
|
|
735
|
+
// });
|
|
728
736
|
resolve(true);
|
|
729
737
|
}
|
|
730
738
|
else {
|
|
@@ -747,17 +755,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
747
755
|
}
|
|
748
756
|
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
749
757
|
_this.sendWS(ws, serverRes);
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
758
|
+
// let endDate = new Date();
|
|
759
|
+
// this.currentPerfomanceMonitor.push({
|
|
760
|
+
// _id: this.idPerformance++,
|
|
761
|
+
// function: 'sendPubDataOnce',
|
|
762
|
+
// publication: subscription.publication,
|
|
763
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
764
|
+
// subscriptionData: [],
|
|
765
|
+
// date_start: startDate,
|
|
766
|
+
// date_end: endDate,
|
|
767
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
768
|
+
// result: 'Send ws spec data'
|
|
769
|
+
// });
|
|
761
770
|
resolve(true);
|
|
762
771
|
}, function (err) {
|
|
763
772
|
var serverRes = {
|
|
@@ -778,11 +787,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
778
787
|
SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
|
|
779
788
|
var _this = this;
|
|
780
789
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
781
|
-
var startDate;
|
|
782
790
|
var _a;
|
|
783
791
|
var _this = this;
|
|
784
792
|
return __generator(this, function (_b) {
|
|
785
|
-
startDate = new Date();
|
|
793
|
+
// let startDate = new Date();
|
|
786
794
|
if (!subscription.clients.length) {
|
|
787
795
|
if (subscription.cacheId) {
|
|
788
796
|
this._nodeCache.del(subscription.cacheId);
|
|
@@ -803,17 +811,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
803
811
|
_this._nodeCache.del(subscription.cacheId);
|
|
804
812
|
}
|
|
805
813
|
_this._subscriptions.splice(_this._subscriptions.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
814
|
+
// let endDate = new Date();
|
|
815
|
+
// this.currentPerfomanceMonitor.push({
|
|
816
|
+
// _id: this.idPerformance++,
|
|
817
|
+
// function: 'sendPubData',
|
|
818
|
+
// publication: subscription.publication,
|
|
819
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
820
|
+
// subscriptionData: [],
|
|
821
|
+
// date_start: startDate,
|
|
822
|
+
// date_end: endDate,
|
|
823
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
824
|
+
// result: 'No clients'
|
|
825
|
+
// });
|
|
817
826
|
resolve(false);
|
|
818
827
|
}
|
|
819
828
|
else {
|
|
@@ -854,17 +863,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
854
863
|
_this._cacheId += 1;
|
|
855
864
|
_this._nodeCache.set(cacheId, JSON.stringify(res));
|
|
856
865
|
subscription.cacheId = cacheId;
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
866
|
+
// let endDate = new Date();
|
|
867
|
+
// this.currentPerfomanceMonitor.push({
|
|
868
|
+
// _id: this.idPerformance++,
|
|
869
|
+
// function: 'sendPubData',
|
|
870
|
+
// publication: subscription.publication,
|
|
871
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
872
|
+
// subscriptionData: [],
|
|
873
|
+
// date_start: startDate,
|
|
874
|
+
// date_end: endDate,
|
|
875
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
876
|
+
// result: 'Same data'
|
|
877
|
+
// });
|
|
868
878
|
}
|
|
869
879
|
resolve(true);
|
|
870
880
|
}
|