@resolveio/server-lib 9.7.7 → 9.7.8
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.
|
@@ -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,133 @@ 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
|
+
newLoggedInUser = {
|
|
489
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
490
|
+
__v: 0,
|
|
491
|
+
date: new Date(),
|
|
492
|
+
id_user: ws['id_user'],
|
|
493
|
+
user: ws['user'],
|
|
494
|
+
id_ws: ws['id_socket']
|
|
495
|
+
};
|
|
496
|
+
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.insertOne(newLoggedInUser)];
|
|
497
|
+
case 1:
|
|
498
|
+
_a.sent();
|
|
499
|
+
this._loggedInUsers.push(newLoggedInUser);
|
|
500
|
+
if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
|
|
501
|
+
this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'supportCreateBillingUser', {
|
|
415
502
|
id_user: ws['id_user'],
|
|
416
|
-
|
|
417
|
-
|
|
503
|
+
user: ws['user'],
|
|
504
|
+
date: new Date(),
|
|
505
|
+
client: index_1.ResolveIOServer.getClientName()
|
|
418
506
|
});
|
|
419
507
|
}
|
|
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
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (publication === 'appversion') {
|
|
475
|
-
newLoggedInUser = {
|
|
476
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
477
|
-
__v: 0,
|
|
478
|
-
date: new Date(),
|
|
479
|
-
id_user: ws['id_user'],
|
|
480
|
-
user: ws['user'],
|
|
481
|
-
id_ws: ws['id_socket']
|
|
482
|
-
};
|
|
483
|
-
this._loggedInUsers.push(newLoggedInUser);
|
|
484
|
-
logged_in_users_collection_1.LoggedInUsers.insertOne(newLoggedInUser);
|
|
485
|
-
if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
|
|
486
|
-
this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'supportCreateBillingUser', {
|
|
487
|
-
id_user: ws['id_user'],
|
|
488
|
-
user: ws['user'],
|
|
489
|
-
date: new Date(),
|
|
490
|
-
client: index_1.ResolveIOServer.getClientName()
|
|
491
|
-
});
|
|
492
|
-
}
|
|
508
|
+
_a.label = 2;
|
|
509
|
+
case 2: return [2 /*return*/];
|
|
493
510
|
}
|
|
494
|
-
return [2 /*return*/];
|
|
495
511
|
});
|
|
496
512
|
});
|
|
497
513
|
};
|
|
@@ -502,9 +518,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
502
518
|
subscriptionData[_i - 4] = arguments[_i];
|
|
503
519
|
}
|
|
504
520
|
return __awaiter(this, void 0, void 0, function () {
|
|
505
|
-
var
|
|
521
|
+
var sub, i;
|
|
506
522
|
return __generator(this, function (_a) {
|
|
507
|
-
startDate = new Date();
|
|
523
|
+
// let startDate = new Date();
|
|
508
524
|
// console.log('Before');
|
|
509
525
|
// console.dir(this._subscriptions.map(a => a.publication));
|
|
510
526
|
if (!this._publications[publication]) {
|
|
@@ -521,17 +537,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
521
537
|
}
|
|
522
538
|
}
|
|
523
539
|
}
|
|
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
540
|
return [2 /*return*/];
|
|
536
541
|
});
|
|
537
542
|
});
|
|
@@ -539,11 +544,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
539
544
|
// Unsubscribe from publication
|
|
540
545
|
SubscriptionManager.prototype.unsubscribeAll = function (ws) {
|
|
541
546
|
return __awaiter(this, void 0, void 0, function () {
|
|
542
|
-
var
|
|
547
|
+
var loggedInUser, userSubs, i, sub, j;
|
|
543
548
|
return __generator(this, function (_a) {
|
|
544
549
|
switch (_a.label) {
|
|
545
550
|
case 0:
|
|
546
|
-
startDate = new Date();
|
|
547
551
|
if (!ws) return [3 /*break*/, 2];
|
|
548
552
|
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findOne({ id_ws: ws['id_socket'] })];
|
|
549
553
|
case 1:
|
|
@@ -564,17 +568,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
564
568
|
}
|
|
565
569
|
}
|
|
566
570
|
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
571
|
_a.label = 2;
|
|
579
572
|
case 2: return [2 /*return*/];
|
|
580
573
|
}
|
|
@@ -590,7 +583,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
590
583
|
var _this = this;
|
|
591
584
|
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
592
585
|
this._oplog.on('change', function (doc) {
|
|
593
|
-
|
|
586
|
+
// let startDate = new Date();
|
|
594
587
|
if (doc.ns) {
|
|
595
588
|
var collection = doc.ns.coll;
|
|
596
589
|
// console.log(new Date(), 'Op log doc', doc.operationType, collection);
|
|
@@ -608,17 +601,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
608
601
|
if (collection !== 'method-responses') {
|
|
609
602
|
_this.invalidatePubsCache(collection, 'insert');
|
|
610
603
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
});
|
|
604
|
+
// let endDate = new Date();
|
|
605
|
+
// this.currentPerfomanceMonitor.push({
|
|
606
|
+
// _id: this.idPerformance++,
|
|
607
|
+
// function: 'oplog',
|
|
608
|
+
// publication: collection,
|
|
609
|
+
// subscriptionData: [],
|
|
610
|
+
// date_start: startDate,
|
|
611
|
+
// date_end: endDate,
|
|
612
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
613
|
+
// result: 'Insert'
|
|
614
|
+
// });
|
|
622
615
|
}
|
|
623
616
|
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
624
617
|
if (collection === 'cron-jobs') {
|
|
@@ -627,17 +620,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
627
620
|
if (collection !== 'method-responses') {
|
|
628
621
|
_this.invalidatePubsCache(collection, 'update');
|
|
629
622
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
});
|
|
623
|
+
// let endDate = new Date();
|
|
624
|
+
// this.currentPerfomanceMonitor.push({
|
|
625
|
+
// _id: this.idPerformance++,
|
|
626
|
+
// function: 'oplog',
|
|
627
|
+
// publication: collection,
|
|
628
|
+
// subscriptionData: [],
|
|
629
|
+
// date_start: startDate,
|
|
630
|
+
// date_end: endDate,
|
|
631
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
632
|
+
// result: 'Update'
|
|
633
|
+
// });
|
|
641
634
|
}
|
|
642
635
|
else if (doc.operationType === 'delete') {
|
|
643
636
|
if (collection === 'cron-jobs') {
|
|
@@ -646,17 +639,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
646
639
|
if (collection !== 'method-responses') {
|
|
647
640
|
_this.invalidatePubsCache(collection, 'delete');
|
|
648
641
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
});
|
|
642
|
+
// let endDate = new Date();
|
|
643
|
+
// this.currentPerfomanceMonitor.push({
|
|
644
|
+
// _id: this.idPerformance++,
|
|
645
|
+
// function: 'oplog',
|
|
646
|
+
// publication: collection,
|
|
647
|
+
// subscriptionData: [],
|
|
648
|
+
// date_start: startDate,
|
|
649
|
+
// date_end: endDate,
|
|
650
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
651
|
+
// result: 'Delete'
|
|
652
|
+
// });
|
|
660
653
|
}
|
|
661
654
|
}
|
|
662
655
|
}
|
|
@@ -674,11 +667,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
674
667
|
SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
|
|
675
668
|
var _this = this;
|
|
676
669
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
677
|
-
var
|
|
670
|
+
var cacheData, serverRes;
|
|
678
671
|
var _a;
|
|
679
672
|
var _this = this;
|
|
680
673
|
return __generator(this, function (_b) {
|
|
681
|
-
startDate = new Date();
|
|
674
|
+
// let startDate = new Date();
|
|
682
675
|
if (!this._publications[subscription.publication].ws_specific) { // Same pub for all users
|
|
683
676
|
if (subscription.cacheId) {
|
|
684
677
|
cacheData = null;
|
|
@@ -714,17 +707,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
714
707
|
run_again: false
|
|
715
708
|
});
|
|
716
709
|
}
|
|
717
|
-
endDate = new Date();
|
|
718
|
-
this.currentPerfomanceMonitor.push({
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
710
|
+
// let endDate = new Date();
|
|
711
|
+
// this.currentPerfomanceMonitor.push({
|
|
712
|
+
// _id: this.idPerformance++,
|
|
713
|
+
// function: 'sendPubDataOnce',
|
|
714
|
+
// publication: subscription.publication,
|
|
715
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
716
|
+
// subscriptionData: [],
|
|
717
|
+
// date_start: startDate,
|
|
718
|
+
// date_end: endDate,
|
|
719
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
720
|
+
// result: 'Send cache'
|
|
721
|
+
// });
|
|
728
722
|
resolve(true);
|
|
729
723
|
}
|
|
730
724
|
else {
|
|
@@ -747,17 +741,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
747
741
|
}
|
|
748
742
|
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
749
743
|
_this.sendWS(ws, serverRes);
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
744
|
+
// let endDate = new Date();
|
|
745
|
+
// this.currentPerfomanceMonitor.push({
|
|
746
|
+
// _id: this.idPerformance++,
|
|
747
|
+
// function: 'sendPubDataOnce',
|
|
748
|
+
// publication: subscription.publication,
|
|
749
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
750
|
+
// subscriptionData: [],
|
|
751
|
+
// date_start: startDate,
|
|
752
|
+
// date_end: endDate,
|
|
753
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
754
|
+
// result: 'Send ws spec data'
|
|
755
|
+
// });
|
|
761
756
|
resolve(true);
|
|
762
757
|
}, function (err) {
|
|
763
758
|
var serverRes = {
|
|
@@ -778,11 +773,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
778
773
|
SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
|
|
779
774
|
var _this = this;
|
|
780
775
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
781
|
-
var startDate;
|
|
782
776
|
var _a;
|
|
783
777
|
var _this = this;
|
|
784
778
|
return __generator(this, function (_b) {
|
|
785
|
-
startDate = new Date();
|
|
779
|
+
// let startDate = new Date();
|
|
786
780
|
if (!subscription.clients.length) {
|
|
787
781
|
if (subscription.cacheId) {
|
|
788
782
|
this._nodeCache.del(subscription.cacheId);
|
|
@@ -803,17 +797,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
803
797
|
_this._nodeCache.del(subscription.cacheId);
|
|
804
798
|
}
|
|
805
799
|
_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
|
-
|
|
800
|
+
// let endDate = new Date();
|
|
801
|
+
// this.currentPerfomanceMonitor.push({
|
|
802
|
+
// _id: this.idPerformance++,
|
|
803
|
+
// function: 'sendPubData',
|
|
804
|
+
// publication: subscription.publication,
|
|
805
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
806
|
+
// subscriptionData: [],
|
|
807
|
+
// date_start: startDate,
|
|
808
|
+
// date_end: endDate,
|
|
809
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
810
|
+
// result: 'No clients'
|
|
811
|
+
// });
|
|
817
812
|
resolve(false);
|
|
818
813
|
}
|
|
819
814
|
else {
|
|
@@ -854,17 +849,18 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
854
849
|
_this._cacheId += 1;
|
|
855
850
|
_this._nodeCache.set(cacheId, JSON.stringify(res));
|
|
856
851
|
subscription.cacheId = cacheId;
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
852
|
+
// let endDate = new Date();
|
|
853
|
+
// this.currentPerfomanceMonitor.push({
|
|
854
|
+
// _id: this.idPerformance++,
|
|
855
|
+
// function: 'sendPubData',
|
|
856
|
+
// publication: subscription.publication,
|
|
857
|
+
// // subscriptionData: subscription.subscriptionData,
|
|
858
|
+
// subscriptionData: [],
|
|
859
|
+
// date_start: startDate,
|
|
860
|
+
// date_end: endDate,
|
|
861
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
862
|
+
// result: 'Same data'
|
|
863
|
+
// });
|
|
868
864
|
}
|
|
869
865
|
resolve(true);
|
|
870
866
|
}
|