@resolveio/server-lib 2.0.4 → 2.0.5

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,11 @@ var SubscriptionManager = /** @class */ (function () {
350
353
  if (nsArray[2]) {
351
354
  collection += '.' + nsArray[2];
352
355
  }
353
- that.checkPubsForChanges(collection, doc.o);
356
+ _this._oplogQueue.push({
357
+ type: 'insert',
358
+ collection: collection,
359
+ doc: doc.o
360
+ });
354
361
  if (collection === 'cron-jobs') {
355
362
  _this._mainServer.getCronManager().checkCronJobsForUpdates();
356
363
  }
@@ -371,7 +378,11 @@ var SubscriptionManager = /** @class */ (function () {
371
378
  collection += '.' + nsArray[2];
372
379
  }
373
380
  doc.o['_id'] = doc.o2['_id'];
374
- that.checkPubsForChanges(collection, doc.o);
381
+ _this._oplogQueue.push({
382
+ type: 'update',
383
+ collection: collection,
384
+ doc: doc.o
385
+ });
375
386
  if (collection === 'cron-jobs') {
376
387
  _this._mainServer.getCronManager().checkCronJobsForUpdates();
377
388
  }
@@ -398,6 +409,34 @@ var SubscriptionManager = /** @class */ (function () {
398
409
  console.log('oplog stopped');
399
410
  });
400
411
  };
412
+ SubscriptionManager.prototype.runOpLogQueue = function () {
413
+ var _this = this;
414
+ setInterval(function () {
415
+ var oplogQueue = common_1.deepCopy(_this._oplogQueue);
416
+ var uniqueCollectionOplogQueue = oplogQueue.map(function (a) { return a.collection; }).filter(function (elem, index, self) {
417
+ return index === self.indexOf(elem);
418
+ });
419
+ uniqueCollectionOplogQueue.forEach(function (collection) {
420
+ var oplogQueueFiltered = oplogQueue.filter(function (a) { return a.collection === collection; });
421
+ if (oplogQueueFiltered.length === 1) {
422
+ _this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
423
+ _this._oplogQueue.splice(oplogQueue.map(collection).indexOf(collection), 1);
424
+ }
425
+ else {
426
+ oplogQueueFiltered.forEach(function (item) {
427
+ _this.checkPubsForChanges(item.collection, item.doc, true);
428
+ });
429
+ _this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc);
430
+ for (var i = _this._oplogQueue.length - 1; i >= 0; i--) {
431
+ var item = _this._oplogQueue[i];
432
+ if (item.collection === collection) {
433
+ _this._oplogQueue.splice(i, 1);
434
+ }
435
+ }
436
+ }
437
+ });
438
+ }, 1000);
439
+ };
401
440
  SubscriptionManager.prototype.tailOpLogSupport = function () {
402
441
  var that = this;
403
442
  var oplog = MongoOplog(that.serverConfig['RESOLVEIO_SUPPORT_OPLOG_URL']);
@@ -466,8 +505,9 @@ var SubscriptionManager = /** @class */ (function () {
466
505
  // Document: Inserted/Modified/Deleted Document
467
506
  // Collection: Collection Document Lives In
468
507
  // Check to see if any pubs need to refetch due to Mongo operation
469
- SubscriptionManager.prototype.checkPubsForChanges = function (collection, document) {
508
+ SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, fetchFunctionOnly) {
470
509
  var _this = this;
510
+ if (fetchFunctionOnly === void 0) { fetchFunctionOnly = false; }
471
511
  var that = this;
472
512
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
473
513
  var _a, schemaErrors, _b;
@@ -509,7 +549,7 @@ var SubscriptionManager = /** @class */ (function () {
509
549
  });
510
550
  }
511
551
  }
512
- else {
552
+ else if (!fetchFunctionOnly) {
513
553
  that._wss.clients.forEach(function (ws) {
514
554
  if (ws['id_socket'] === client.id_socket) {
515
555
  that.sendPubDataOnce(ws, client.messageId, sub);
@@ -524,7 +564,7 @@ var SubscriptionManager = /** @class */ (function () {
524
564
  that.sendPubData(sub);
525
565
  }
526
566
  }
527
- else {
567
+ else if (!fetchFunctionOnly) {
528
568
  that.sendPubData(sub);
529
569
  }
530
570
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {