@resolveio/server-lib 2.0.4 → 2.0.6
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.
|
@@ -5,6 +5,7 @@ export declare class SubscriptionManager {
|
|
|
5
5
|
private _publications;
|
|
6
6
|
private _subscriptions;
|
|
7
7
|
private _wss;
|
|
8
|
+
private _oplogQueue;
|
|
8
9
|
private _sendQueue;
|
|
9
10
|
private _runningQueue;
|
|
10
11
|
private serverConfig;
|
|
@@ -16,6 +17,7 @@ export declare class SubscriptionManager {
|
|
|
16
17
|
unsubscribeAll(ws: WebSocket): Promise<void>;
|
|
17
18
|
private getPublicationCollections;
|
|
18
19
|
private tailOpLog;
|
|
20
|
+
private runOpLogQueue;
|
|
19
21
|
private tailOpLogSupport;
|
|
20
22
|
private resendPubsForDelete;
|
|
21
23
|
private checkPubsForChanges;
|
|
@@ -51,11 +51,13 @@ var method_responses_1 = require("../publications/method-responses");
|
|
|
51
51
|
var support_tickets_1 = require("../publications/support-tickets");
|
|
52
52
|
var index_1 = require("../index");
|
|
53
53
|
var notifications_1 = require("../publications/notifications");
|
|
54
|
+
var common_1 = require("../util/common");
|
|
54
55
|
var SubscriptionManager = /** @class */ (function () {
|
|
55
56
|
function SubscriptionManager(mainServer, wss, serverConfig) {
|
|
56
57
|
var _this = this;
|
|
57
58
|
this._publications = {};
|
|
58
59
|
this._subscriptions = [];
|
|
60
|
+
this._oplogQueue = [];
|
|
59
61
|
this._sendQueue = [];
|
|
60
62
|
this._runningQueue = false;
|
|
61
63
|
this._mainServer = mainServer;
|
|
@@ -74,6 +76,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
74
76
|
support_tickets_1.loadSupportTicketPublications(this);
|
|
75
77
|
notifications_1.loadNotificationPublications(this);
|
|
76
78
|
this.tailOpLog();
|
|
79
|
+
this.runOpLogQueue();
|
|
77
80
|
if (index_1.ResolveIOServer.getSupportDB()) {
|
|
78
81
|
this.tailOpLogSupport();
|
|
79
82
|
}
|
|
@@ -350,7 +353,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
350
353
|
if (nsArray[2]) {
|
|
351
354
|
collection += '.' + nsArray[2];
|
|
352
355
|
}
|
|
353
|
-
that.checkPubsForChanges(collection, doc.o);
|
|
354
356
|
if (collection === 'cron-jobs') {
|
|
355
357
|
_this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
356
358
|
}
|
|
@@ -363,6 +365,13 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
363
365
|
else if (collection === 'support-tickets') {
|
|
364
366
|
_this._mainServer.getMethodManager().callMethodInternal('sendSupportTicketEmail', doc.o._id);
|
|
365
367
|
}
|
|
368
|
+
else {
|
|
369
|
+
_this._oplogQueue.push({
|
|
370
|
+
type: 'insert',
|
|
371
|
+
collection: collection,
|
|
372
|
+
doc: doc.o
|
|
373
|
+
});
|
|
374
|
+
}
|
|
366
375
|
});
|
|
367
376
|
oplog.on('update', function (doc) {
|
|
368
377
|
var nsArray = doc.ns.split('.');
|
|
@@ -371,10 +380,16 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
371
380
|
collection += '.' + nsArray[2];
|
|
372
381
|
}
|
|
373
382
|
doc.o['_id'] = doc.o2['_id'];
|
|
374
|
-
that.checkPubsForChanges(collection, doc.o);
|
|
375
383
|
if (collection === 'cron-jobs') {
|
|
376
384
|
_this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
377
385
|
}
|
|
386
|
+
else {
|
|
387
|
+
_this._oplogQueue.push({
|
|
388
|
+
type: 'update',
|
|
389
|
+
collection: collection,
|
|
390
|
+
doc: doc.o
|
|
391
|
+
});
|
|
392
|
+
}
|
|
378
393
|
});
|
|
379
394
|
oplog.on('delete', function (doc) {
|
|
380
395
|
var nsArray = doc.ns.split('.');
|
|
@@ -398,6 +413,34 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
398
413
|
console.log('oplog stopped');
|
|
399
414
|
});
|
|
400
415
|
};
|
|
416
|
+
SubscriptionManager.prototype.runOpLogQueue = function () {
|
|
417
|
+
var _this = this;
|
|
418
|
+
setInterval(function () {
|
|
419
|
+
var oplogQueue = common_1.deepCopy(_this._oplogQueue);
|
|
420
|
+
var uniqueCollectionOplogQueue = oplogQueue.map(function (a) { return a.collection; }).filter(function (elem, index, self) {
|
|
421
|
+
return index === self.indexOf(elem);
|
|
422
|
+
});
|
|
423
|
+
uniqueCollectionOplogQueue.forEach(function (collection) {
|
|
424
|
+
var oplogQueueFiltered = oplogQueue.filter(function (a) { return a.collection === collection; });
|
|
425
|
+
if (oplogQueueFiltered.length === 1) {
|
|
426
|
+
_this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
|
|
427
|
+
_this._oplogQueue.splice(oplogQueue.map(collection).indexOf(collection), 1);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
oplogQueueFiltered.forEach(function (item) {
|
|
431
|
+
_this.checkPubsForChanges(item.collection, item.doc, true);
|
|
432
|
+
});
|
|
433
|
+
_this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc);
|
|
434
|
+
for (var i = _this._oplogQueue.length - 1; i >= 0; i--) {
|
|
435
|
+
var item = _this._oplogQueue[i];
|
|
436
|
+
if (item.collection === collection) {
|
|
437
|
+
_this._oplogQueue.splice(i, 1);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}, 1000);
|
|
443
|
+
};
|
|
401
444
|
SubscriptionManager.prototype.tailOpLogSupport = function () {
|
|
402
445
|
var that = this;
|
|
403
446
|
var oplog = MongoOplog(that.serverConfig['RESOLVEIO_SUPPORT_OPLOG_URL']);
|
|
@@ -466,8 +509,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
466
509
|
// Document: Inserted/Modified/Deleted Document
|
|
467
510
|
// Collection: Collection Document Lives In
|
|
468
511
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
469
|
-
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document) {
|
|
512
|
+
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, fetchFunctionOnly) {
|
|
470
513
|
var _this = this;
|
|
514
|
+
if (fetchFunctionOnly === void 0) { fetchFunctionOnly = false; }
|
|
471
515
|
var that = this;
|
|
472
516
|
that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
|
|
473
517
|
var _a, schemaErrors, _b;
|
|
@@ -509,7 +553,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
509
553
|
});
|
|
510
554
|
}
|
|
511
555
|
}
|
|
512
|
-
else {
|
|
556
|
+
else if (!fetchFunctionOnly) {
|
|
513
557
|
that._wss.clients.forEach(function (ws) {
|
|
514
558
|
if (ws['id_socket'] === client.id_socket) {
|
|
515
559
|
that.sendPubDataOnce(ws, client.messageId, sub);
|
|
@@ -524,7 +568,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
524
568
|
that.sendPubData(sub);
|
|
525
569
|
}
|
|
526
570
|
}
|
|
527
|
-
else {
|
|
571
|
+
else if (!fetchFunctionOnly) {
|
|
528
572
|
that.sendPubData(sub);
|
|
529
573
|
}
|
|
530
574
|
}
|