@resolveio/server-lib 4.1.5 → 4.2.0

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.
@@ -51,6 +51,7 @@ 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 billing_logged_in_users_collection_1 = require("../collections/billing-logged-in-users.collection");
55
56
  var moment = require("moment");
56
57
  var billing_logged_in_users_1 = require("../publications/billing-logged-in-users");
@@ -501,35 +502,144 @@ var SubscriptionManager = /** @class */ (function () {
501
502
  };
502
503
  SubscriptionManager.prototype.runOpLogQueue = function () {
503
504
  var _this = this;
505
+ var that = this;
504
506
  setInterval(function () {
505
507
  if (_this._oplogQueue.length) {
506
- var oplog = _this._oplogQueue.pop();
507
- _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
508
+ var oplogQueue_1 = common_1.deepCopy(_this._oplogQueue);
509
+ _this._oplogQueue = [];
510
+ var uniquePubs_1 = [];
511
+ var uniqueOplog_1 = [];
512
+ var needIds_1 = {};
513
+ oplogQueue_1.forEach(function (oplog) {
514
+ for (var i = 0; i < that._subscriptions.length; i++) {
515
+ var sub = that._subscriptions[i];
516
+ if (sub.collections.includes(oplog.collection)) {
517
+ var schemaErrors = null;
518
+ try {
519
+ index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(sub.preSubscriptionData);
520
+ }
521
+ catch (errors) {
522
+ schemaErrors = errors;
523
+ }
524
+ if (schemaErrors) {
525
+ if (!needIds_1[oplog.collection]) {
526
+ needIds_1[oplog.collection] = [oplog.doc['_id']];
527
+ }
528
+ else {
529
+ if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
530
+ needIds_1[oplog.collection].push(oplog.doc['_id']);
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }
536
+ });
537
+ Object.keys(needIds_1).forEach(function (collection) { return __awaiter(_this, void 0, void 0, function () {
538
+ var docs;
539
+ return __generator(this, function (_a) {
540
+ switch (_a.label) {
541
+ case 0: return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).find({ _id: { $in: needIds_1[collection] } })];
542
+ case 1:
543
+ docs = _a.sent();
544
+ needIds_1[collection].forEach(function (id_doc) {
545
+ oplogQueue_1.filter(function (a) { return a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; });
546
+ });
547
+ return [2 /*return*/];
548
+ }
549
+ });
550
+ }); });
551
+ oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
552
+ var _loop_3, i;
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0:
556
+ _loop_3 = function (i) {
557
+ var sub, _a;
558
+ var _b;
559
+ return __generator(this, function (_c) {
560
+ switch (_c.label) {
561
+ case 0:
562
+ sub = that._subscriptions[i];
563
+ if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 3];
564
+ if (sub.preSubscriptionData) {
565
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
566
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)[0]; })) {
567
+ uniquePubs_1.push(sub);
568
+ uniqueOplog_1.push(oplog);
569
+ }
570
+ return [2 /*return*/, "continue"];
571
+ }
572
+ }
573
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
574
+ _a = sub;
575
+ return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
576
+ case 1:
577
+ _a.preSubscriptionData = _c.sent();
578
+ if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
579
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
580
+ uniquePubs_1.push(sub);
581
+ uniqueOplog_1.push(oplog);
582
+ }
583
+ return [2 /*return*/, "continue"];
584
+ }
585
+ return [3 /*break*/, 3];
586
+ case 2:
587
+ if (that._publications[sub.publication].ws_specific) {
588
+ sub.clients.forEach(function (client) {
589
+ var _a;
590
+ if (that._publications[sub.publication].fetchFunction) {
591
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
592
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
593
+ uniquePubs_1.push(sub);
594
+ uniqueOplog_1.push(oplog);
595
+ }
596
+ }
597
+ }
598
+ });
599
+ }
600
+ else {
601
+ if (that._publications[sub.publication].fetchFunction) {
602
+ if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
603
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
604
+ uniquePubs_1.push(sub);
605
+ uniqueOplog_1.push(oplog);
606
+ }
607
+ return [2 /*return*/, "continue"];
608
+ }
609
+ }
610
+ else {
611
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
612
+ uniquePubs_1.push(sub);
613
+ uniqueOplog_1.push(oplog);
614
+ }
615
+ return [2 /*return*/, "continue"];
616
+ }
617
+ }
618
+ _c.label = 3;
619
+ case 3: return [2 /*return*/];
620
+ }
621
+ });
622
+ };
623
+ i = 0;
624
+ _a.label = 1;
625
+ case 1:
626
+ if (!(i < that._subscriptions.length)) return [3 /*break*/, 4];
627
+ return [5 /*yield**/, _loop_3(i)];
628
+ case 2:
629
+ _a.sent();
630
+ _a.label = 3;
631
+ case 3:
632
+ i++;
633
+ return [3 /*break*/, 1];
634
+ case 4: return [2 /*return*/];
635
+ }
636
+ });
637
+ }); });
638
+ uniqueOplog_1.forEach(function (oplog) {
639
+ _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
640
+ });
508
641
  }
509
- // let oplogQueue = deepCopy(this._oplogQueue);
510
- // let uniqueCollectionOplogQueue = oplogQueue.map(a => a.collection).filter((elem, index, self) => {
511
- // return index === self.indexOf(elem);
512
- // });
513
- // uniqueCollectionOplogQueue.forEach(collection => {
514
- // let oplogQueueFiltered = oplogQueue.filter(a => a.collection === collection);
515
- // if (oplogQueueFiltered.length === 1) {
516
- // this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
517
- // this._oplogQueue.splice(this._oplogQueue.map(a => a.collection).indexOf(collection), 1);
518
- // }
519
- // else {
520
- // oplogQueueFiltered.forEach(item => {
521
- // this.checkPubsForChanges(item.collection, item.doc, true);
522
- // });
523
- // this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc, false, true);
524
- // for (let i = this._oplogQueue.length - 1; i >= 0; i--) {
525
- // let item = this._oplogQueue[i];
526
- // if (item.collection === collection) {
527
- // this._oplogQueue.splice(i, 1);
528
- // }
529
- // }
530
- // }
531
- // });
532
- }, 25);
642
+ }, 100);
533
643
  };
534
644
  SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
535
645
  var that = this;
@@ -582,7 +692,7 @@ var SubscriptionManager = /** @class */ (function () {
582
692
  return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
583
693
  case 3:
584
694
  _a.preSubscriptionData = _e.sent();
585
- return [2 /*return*/];
695
+ _e.label = 4;
586
696
  case 4:
587
697
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 7];
588
698
  if (!!noFetchFunction) return [3 /*break*/, 6];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.1.5",
3
+ "version": "4.2.0",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {