@resolveio/server-lib 4.2.6 → 4.2.8-debug

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.
@@ -504,105 +504,133 @@ var SubscriptionManager = /** @class */ (function () {
504
504
  SubscriptionManager.prototype.runOpLogQueue = function () {
505
505
  var _this = this;
506
506
  var that = this;
507
- setInterval(function () {
508
- if (_this._oplogQueue.length) {
509
- var oplogQueue_1 = common_1.deepCopy(_this._oplogQueue);
510
- _this._oplogQueue = [];
511
- var uniquePubs_1 = [];
512
- var uniqueOplog_1 = [];
513
- var needIds_1 = {};
514
- oplogQueue_1.forEach(function (oplog) {
515
- for (var i = 0; i < that._subscriptions.length; i++) {
516
- var sub = that._subscriptions[i];
517
- if (sub.collections.includes(oplog.collection)) {
518
- var schemaErrors = null;
519
- try {
520
- index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(sub.preSubscriptionData);
521
- }
522
- catch (errors) {
523
- schemaErrors = errors;
524
- }
525
- if (schemaErrors) {
526
- if (!needIds_1[oplog.collection]) {
527
- needIds_1[oplog.collection] = [oplog.doc['_id']];
528
- }
529
- else {
530
- if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
531
- needIds_1[oplog.collection].push(oplog.doc['_id']);
507
+ setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
508
+ var oplogQueue_1, uniquePubs_1, uniqueOplog_1, needIds_1, _loop_3, i;
509
+ var _this = this;
510
+ return __generator(this, function (_a) {
511
+ switch (_a.label) {
512
+ case 0:
513
+ if (!this._oplogQueue.length) return [3 /*break*/, 5];
514
+ oplogQueue_1 = common_1.deepCopy(this._oplogQueue);
515
+ this._oplogQueue = [];
516
+ uniquePubs_1 = [];
517
+ uniqueOplog_1 = [];
518
+ needIds_1 = {};
519
+ console.log('----------------OPLOG QUEUE START BEFORE DATA--------------------', new Date(), oplogQueue_1.length);
520
+ oplogQueue_1.forEach(function (oplog) {
521
+ for (var i = 0; i < that._subscriptions.length; i++) {
522
+ var sub = that._subscriptions[i];
523
+ if (sub.collections.includes(oplog.collection)) {
524
+ var schemaErrors = null;
525
+ try {
526
+ index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(oplog.doc);
532
527
  }
533
- }
534
- }
535
- }
536
- }
537
- });
538
- Object.keys(needIds_1).forEach(function (collection) { return __awaiter(_this, void 0, void 0, function () {
539
- var docs;
540
- return __generator(this, function (_a) {
541
- switch (_a.label) {
542
- case 0: return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).find({ _id: { $in: needIds_1[collection] } })];
543
- case 1:
544
- docs = _a.sent();
545
- needIds_1[collection].forEach(function (id_doc) {
546
- oplogQueue_1.filter(function (a) { return a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; });
547
- });
548
- return [2 /*return*/];
549
- }
550
- });
551
- }); });
552
- oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
553
- var _loop_3, i;
554
- return __generator(this, function (_a) {
555
- _loop_3 = function (i) {
556
- var _a;
557
- var sub = that._subscriptions[i];
558
- if (sub.collections.includes(oplog.collection)) {
559
- if (sub.preSubscriptionData) {
560
- if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
561
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
562
- uniquePubs_1.push(sub);
563
- uniqueOplog_1.push(oplog);
528
+ catch (errors) {
529
+ schemaErrors = errors;
530
+ }
531
+ if (schemaErrors) {
532
+ if (!needIds_1[oplog.collection]) {
533
+ needIds_1[oplog.collection] = [oplog.doc['_id']];
534
+ }
535
+ else {
536
+ if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
537
+ needIds_1[oplog.collection].push(oplog.doc['_id']);
538
+ }
564
539
  }
565
- return "continue";
566
540
  }
567
541
  }
568
- if (that._publications[sub.publication].preFunction) {
569
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
570
- uniquePubs_1.push(sub);
571
- uniqueOplog_1.push(oplog);
572
- }
573
- return "continue";
542
+ }
543
+ });
544
+ console.log('Need IDs:', needIds_1);
545
+ _loop_3 = function (i) {
546
+ var collection, docs;
547
+ return __generator(this, function (_a) {
548
+ switch (_a.label) {
549
+ case 0:
550
+ collection = Object.keys(needIds_1)[i];
551
+ return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).find({ _id: { $in: needIds_1[collection] } })];
552
+ case 1:
553
+ docs = _a.sent();
554
+ needIds_1[collection].forEach(function (id_doc) {
555
+ oplogQueue_1.filter(function (a) { return a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; });
556
+ });
557
+ return [2 /*return*/];
574
558
  }
575
- else {
576
- if (that._publications[sub.publication].fetchFunction) {
577
- if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) {
559
+ });
560
+ };
561
+ i = 0;
562
+ _a.label = 1;
563
+ case 1:
564
+ if (!(i < Object.keys(needIds_1).length)) return [3 /*break*/, 4];
565
+ return [5 /*yield**/, _loop_3(i)];
566
+ case 2:
567
+ _a.sent();
568
+ _a.label = 3;
569
+ case 3:
570
+ i++;
571
+ return [3 /*break*/, 1];
572
+ case 4:
573
+ console.log('----------------OPLOG QUEUE START AFTER DATA--------------------', new Date(), oplogQueue_1.length);
574
+ oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
575
+ var _loop_4, i;
576
+ return __generator(this, function (_a) {
577
+ console.log('OPLOG QUEUE START - Oplog', oplog);
578
+ _loop_4 = function (i) {
579
+ var _a;
580
+ var sub = that._subscriptions[i];
581
+ if (sub.collections.includes(oplog.collection)) {
582
+ if (sub.preSubscriptionData) {
583
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
584
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
585
+ uniquePubs_1.push(sub);
586
+ uniqueOplog_1.push(oplog);
587
+ }
588
+ return "continue";
589
+ }
590
+ }
591
+ if (that._publications[sub.publication].preFunction) {
578
592
  if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
579
593
  uniquePubs_1.push(sub);
580
594
  uniqueOplog_1.push(oplog);
581
595
  }
582
596
  return "continue";
583
597
  }
584
- }
585
- else {
586
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
587
- uniquePubs_1.push(sub);
588
- uniqueOplog_1.push(oplog);
598
+ else {
599
+ if (that._publications[sub.publication].fetchFunction) {
600
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) {
601
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
602
+ uniquePubs_1.push(sub);
603
+ uniqueOplog_1.push(oplog);
604
+ }
605
+ return "continue";
606
+ }
607
+ }
608
+ else {
609
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
610
+ uniquePubs_1.push(sub);
611
+ uniqueOplog_1.push(oplog);
612
+ }
613
+ return "continue";
614
+ }
589
615
  }
590
- return "continue";
591
616
  }
617
+ };
618
+ for (i = 0; i < that._subscriptions.length; i++) {
619
+ _loop_4(i);
592
620
  }
593
- }
594
- };
595
- for (i = 0; i < that._subscriptions.length; i++) {
596
- _loop_3(i);
597
- }
598
- return [2 /*return*/];
599
- });
600
- }); });
601
- uniqueOplog_1.forEach(function (oplog) {
602
- _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
603
- });
604
- }
605
- }, 100);
621
+ return [2 /*return*/];
622
+ });
623
+ }); });
624
+ console.log('----------------OPLOG QUEUE END--------------------', new Date(), uniqueOplog_1.length);
625
+ uniqueOplog_1.forEach(function (oplog) {
626
+ console.log('OPLOG QUEUE END - Oplog', oplog);
627
+ _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
628
+ });
629
+ _a.label = 5;
630
+ case 5: return [2 /*return*/];
631
+ }
632
+ });
633
+ }); }, 100);
606
634
  };
607
635
  SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
608
636
  var that = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.2.6",
3
+ "version": "4.2.8-debug",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {