@resolveio/server-lib 5.0.12-debug-1 → 5.0.12-debug-2
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.
|
@@ -56,6 +56,7 @@ var billing_logged_in_users_collection_1 = require("../collections/billing-logge
|
|
|
56
56
|
var moment = require("moment");
|
|
57
57
|
var billing_logged_in_users_1 = require("../publications/billing-logged-in-users");
|
|
58
58
|
var report_builder_reports_1 = require("../publications/report-builder-reports");
|
|
59
|
+
var NodeCache = require("node-cache");
|
|
59
60
|
var SubscriptionManager = /** @class */ (function () {
|
|
60
61
|
function SubscriptionManager(mainServer, wss, serverConfig) {
|
|
61
62
|
var _this = this;
|
|
@@ -63,9 +64,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
63
64
|
this._subscriptions = [];
|
|
64
65
|
this._oplogQueue = [];
|
|
65
66
|
this._subCache = [];
|
|
67
|
+
this._cacheId = 0;
|
|
66
68
|
this._sendQueue = [];
|
|
67
69
|
this._runningQueue = false;
|
|
68
70
|
this._mainServer = mainServer;
|
|
71
|
+
this._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 120 });
|
|
69
72
|
this.serverConfig = serverConfig;
|
|
70
73
|
this._wss = wss;
|
|
71
74
|
// Publications
|
|
@@ -671,6 +674,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
671
674
|
var that = this;
|
|
672
675
|
for (var jj = this._subCache.length - 1; jj >= 0; jj--) {
|
|
673
676
|
if (this._subCache[jj].collection === collection) {
|
|
677
|
+
this._nodeCache.del(this._subCache[jj].id);
|
|
674
678
|
this._subCache.splice(jj, 1);
|
|
675
679
|
}
|
|
676
680
|
}
|
|
@@ -719,6 +723,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
719
723
|
}).exec();
|
|
720
724
|
removed = true;
|
|
721
725
|
}
|
|
726
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
722
727
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
723
728
|
}
|
|
724
729
|
if (!!removed) return [3 /*break*/, 2];
|
|
@@ -748,6 +753,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
748
753
|
}).exec();
|
|
749
754
|
removed = true;
|
|
750
755
|
}
|
|
756
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
751
757
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
752
758
|
}
|
|
753
759
|
if (!removed) {
|
|
@@ -792,6 +798,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
792
798
|
}).exec();
|
|
793
799
|
removed = true;
|
|
794
800
|
}
|
|
801
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
795
802
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
796
803
|
}
|
|
797
804
|
if (!removed) {
|
|
@@ -813,6 +820,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
813
820
|
}).exec();
|
|
814
821
|
removed = true;
|
|
815
822
|
}
|
|
823
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
816
824
|
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
817
825
|
}
|
|
818
826
|
if (!removed) {
|
|
@@ -931,9 +939,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
931
939
|
serverRes = {
|
|
932
940
|
messageId: messageId,
|
|
933
941
|
hasError: false,
|
|
934
|
-
data: this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].
|
|
942
|
+
data: this._nodeCache.get(this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id)
|
|
935
943
|
};
|
|
936
|
-
console.log('Cache1: ' + 'Found - ' + subscription.publication + ' - ' + common_1.getBinarySize(JSON.stringify(this._subCache)));
|
|
937
944
|
this.sendWS(ws, serverRes);
|
|
938
945
|
}
|
|
939
946
|
else {
|
|
@@ -941,20 +948,22 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
941
948
|
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
942
949
|
}
|
|
943
950
|
(_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
|
|
944
|
-
|
|
945
|
-
|
|
951
|
+
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
952
|
+
if (nodeCacheSize > 500000000) {
|
|
946
953
|
var neededSizeIndex = 0;
|
|
947
954
|
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
955
|
+
_this._nodeCache.del(_this._subCache[zz].id);
|
|
956
|
+
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
957
|
+
neededSizeIndex = zz;
|
|
951
958
|
break;
|
|
952
959
|
}
|
|
953
960
|
}
|
|
954
961
|
console.log('Cache1: ' + 'Too Big - ' + subscription.publication + ' - ' + common_1.getBinarySize(JSON.stringify(_this._subCache)));
|
|
955
962
|
_this._subCache.splice(0, neededSizeIndex);
|
|
956
963
|
}
|
|
957
|
-
|
|
964
|
+
var cacheId = _this._cacheId++;
|
|
965
|
+
_this._nodeCache.set(cacheId, res);
|
|
966
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
958
967
|
console.log('Cache1: ' + 'Create - ' + subscription.publication + ' - ' + common_1.getBinarySize(JSON.stringify(_this._subCache)));
|
|
959
968
|
var serverRes = {
|
|
960
969
|
messageId: messageId,
|
|
@@ -1009,7 +1018,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1009
1018
|
var serverRes = {
|
|
1010
1019
|
messageId: client.messageId,
|
|
1011
1020
|
hasError: false,
|
|
1012
|
-
data: _this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].
|
|
1021
|
+
data: _this._nodeCache.get(_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id)
|
|
1013
1022
|
};
|
|
1014
1023
|
console.log('Cache: ' + 'Found - ' + subscription.publication + ' - ' + common_1.getBinarySize(JSON.stringify(_this._subCache)));
|
|
1015
1024
|
_this.sendWS(ws, serverRes);
|
|
@@ -1022,20 +1031,22 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1022
1031
|
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
1023
1032
|
}
|
|
1024
1033
|
(_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1034
|
+
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
1035
|
+
if (nodeCacheSize > 500000000) {
|
|
1027
1036
|
var neededSizeIndex = 0;
|
|
1028
1037
|
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1038
|
+
_this._nodeCache.del(_this._subCache[zz].id);
|
|
1039
|
+
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
1040
|
+
neededSizeIndex = zz;
|
|
1032
1041
|
break;
|
|
1033
1042
|
}
|
|
1034
1043
|
}
|
|
1035
1044
|
console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + common_1.getBinarySize(JSON.stringify(_this._subCache)));
|
|
1036
1045
|
_this._subCache.splice(0, neededSizeIndex);
|
|
1037
1046
|
}
|
|
1038
|
-
|
|
1047
|
+
var cacheId = _this._cacheId++;
|
|
1048
|
+
_this._nodeCache.set(cacheId, res);
|
|
1049
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
1039
1050
|
console.log('Cache: ' + 'Create - ' + subscription.publication + ' - ' + common_1.getBinarySize(JSON.stringify(_this._subCache)));
|
|
1040
1051
|
subscription.clients.forEach(function (client) {
|
|
1041
1052
|
that._wss.clients.forEach(function (ws) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolveio/server-lib",
|
|
3
|
-
"version": "5.0.12-debug-
|
|
3
|
+
"version": "5.0.12-debug-2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"mongo-oplog": "2.1.4",
|
|
28
28
|
"mongoose": "5.6.0",
|
|
29
29
|
"node-google-timezone": "0.1.1",
|
|
30
|
+
"node-cache": "5.0.1",
|
|
30
31
|
"nodemailer": "6.2.1",
|
|
31
32
|
"passport": "0.4.0",
|
|
32
33
|
"passport-local": "1.0.0",
|