@resolveio/server-lib 5.0.12 → 5.0.13-newrole
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.
|
@@ -22,13 +22,6 @@ var schema = {
|
|
|
22
22
|
type: Date,
|
|
23
23
|
optional: true
|
|
24
24
|
},
|
|
25
|
-
readonly: {
|
|
26
|
-
type: Boolean,
|
|
27
|
-
optional: true
|
|
28
|
-
},
|
|
29
|
-
active: {
|
|
30
|
-
type: Boolean
|
|
31
|
-
},
|
|
32
25
|
attempts: {
|
|
33
26
|
type: Number,
|
|
34
27
|
optional: true
|
|
@@ -65,53 +58,67 @@ var schema = {
|
|
|
65
58
|
type: String
|
|
66
59
|
},
|
|
67
60
|
roles: {
|
|
61
|
+
type: Object
|
|
62
|
+
},
|
|
63
|
+
'roles.super_admin': {
|
|
64
|
+
type: Boolean
|
|
65
|
+
},
|
|
66
|
+
'roles.approvals': {
|
|
68
67
|
type: Array
|
|
69
68
|
},
|
|
70
|
-
'roles.$': {
|
|
69
|
+
'roles.approvals.$': {
|
|
70
|
+
type: Object
|
|
71
|
+
},
|
|
72
|
+
'roles.approvals.$.name': {
|
|
71
73
|
type: String
|
|
72
74
|
},
|
|
73
|
-
|
|
74
|
-
type: String
|
|
75
|
-
optional: true
|
|
75
|
+
'roles.approvals.$.type': {
|
|
76
|
+
type: String
|
|
76
77
|
},
|
|
77
|
-
|
|
78
|
-
type:
|
|
79
|
-
blackbox: true,
|
|
80
|
-
optional: true
|
|
78
|
+
'roles.approvals.$.accounting_code': {
|
|
79
|
+
type: String
|
|
81
80
|
},
|
|
82
|
-
|
|
83
|
-
type: Array
|
|
84
|
-
optional: true
|
|
81
|
+
'roles.groups': {
|
|
82
|
+
type: Array
|
|
85
83
|
},
|
|
86
|
-
'
|
|
84
|
+
'roles.groups.$': {
|
|
87
85
|
type: Object
|
|
88
86
|
},
|
|
89
|
-
'
|
|
87
|
+
'roles.groups.$.name': {
|
|
90
88
|
type: String
|
|
91
89
|
},
|
|
92
|
-
'
|
|
93
|
-
type:
|
|
90
|
+
'roles.groups.$.views': {
|
|
91
|
+
type: Array
|
|
94
92
|
},
|
|
95
|
-
'
|
|
93
|
+
'roles.groups.$.views.$': {
|
|
96
94
|
type: String
|
|
97
95
|
},
|
|
98
|
-
'
|
|
99
|
-
type: String
|
|
96
|
+
'roles.groups.$.yard': {
|
|
97
|
+
type: String,
|
|
98
|
+
optional: true
|
|
99
|
+
},
|
|
100
|
+
'roles.notifications': {
|
|
101
|
+
type: Array
|
|
100
102
|
},
|
|
101
|
-
'
|
|
103
|
+
'roles.notifications.$': {
|
|
102
104
|
type: String
|
|
103
105
|
},
|
|
104
|
-
'
|
|
105
|
-
type:
|
|
106
|
+
'roles.miscs': {
|
|
107
|
+
type: Array
|
|
106
108
|
},
|
|
107
|
-
'
|
|
108
|
-
type:
|
|
109
|
-
optional: true
|
|
109
|
+
'roles.miscs.$': {
|
|
110
|
+
type: String
|
|
110
111
|
},
|
|
111
|
-
|
|
112
|
+
active: Boolean,
|
|
113
|
+
phonenumber: {
|
|
112
114
|
type: String,
|
|
113
115
|
optional: true
|
|
114
116
|
},
|
|
117
|
+
other: {
|
|
118
|
+
type: Object,
|
|
119
|
+
optional: true,
|
|
120
|
+
blackbox: true
|
|
121
|
+
},
|
|
115
122
|
customers: {
|
|
116
123
|
type: Array,
|
|
117
124
|
optional: true,
|
package/fixtures/init.js
CHANGED
|
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
var app_version_collection_1 = require("../collections/app-version.collection");
|
|
39
39
|
var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
|
|
40
|
-
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
41
40
|
var mongoose_1 = require("mongoose");
|
|
41
|
+
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
42
42
|
function loadServerInit() {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
44
|
var appVersion;
|
|
@@ -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
|
|
@@ -87,6 +90,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
87
90
|
support_tickets_1.loadSupportTicketPublications(this);
|
|
88
91
|
this.tailOpLogSupport();
|
|
89
92
|
}
|
|
93
|
+
setInterval(function () {
|
|
94
|
+
console.log(_this._nodeCache.getStats().vsize);
|
|
95
|
+
}, 60000);
|
|
90
96
|
setInterval(function () {
|
|
91
97
|
if (!_this._runningQueue) {
|
|
92
98
|
if (_this._sendQueue.length) {
|
|
@@ -671,6 +677,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
671
677
|
var that = this;
|
|
672
678
|
for (var jj = this._subCache.length - 1; jj >= 0; jj--) {
|
|
673
679
|
if (this._subCache[jj].collection === collection) {
|
|
680
|
+
this._nodeCache.del(this._subCache[jj].id);
|
|
674
681
|
this._subCache.splice(jj, 1);
|
|
675
682
|
}
|
|
676
683
|
}
|
|
@@ -719,6 +726,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
719
726
|
}).exec();
|
|
720
727
|
removed = true;
|
|
721
728
|
}
|
|
729
|
+
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
730
|
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
731
|
}
|
|
724
732
|
if (!!removed) return [3 /*break*/, 2];
|
|
@@ -748,6 +756,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
748
756
|
}).exec();
|
|
749
757
|
removed = true;
|
|
750
758
|
}
|
|
759
|
+
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
760
|
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
761
|
}
|
|
753
762
|
if (!removed) {
|
|
@@ -792,6 +801,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
792
801
|
}).exec();
|
|
793
802
|
removed = true;
|
|
794
803
|
}
|
|
804
|
+
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
805
|
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
806
|
}
|
|
797
807
|
if (!removed) {
|
|
@@ -813,6 +823,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
813
823
|
}).exec();
|
|
814
824
|
removed = true;
|
|
815
825
|
}
|
|
826
|
+
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
827
|
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
828
|
}
|
|
818
829
|
if (!removed) {
|
|
@@ -931,7 +942,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
931
942
|
serverRes = {
|
|
932
943
|
messageId: messageId,
|
|
933
944
|
hasError: false,
|
|
934
|
-
data: this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].
|
|
945
|
+
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
946
|
};
|
|
936
947
|
this.sendWS(ws, serverRes);
|
|
937
948
|
}
|
|
@@ -940,19 +951,23 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
940
951
|
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
941
952
|
}
|
|
942
953
|
(_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
|
|
943
|
-
|
|
944
|
-
|
|
954
|
+
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
955
|
+
if (nodeCacheSize > 500000000) {
|
|
945
956
|
var neededSizeIndex = 0;
|
|
946
957
|
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
958
|
+
_this._nodeCache.del(_this._subCache[zz].id);
|
|
959
|
+
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
960
|
+
neededSizeIndex = zz;
|
|
950
961
|
break;
|
|
951
962
|
}
|
|
952
963
|
}
|
|
964
|
+
// console.log('Cache1: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
953
965
|
_this._subCache.splice(0, neededSizeIndex);
|
|
954
966
|
}
|
|
955
|
-
|
|
967
|
+
var cacheId = _this._cacheId++;
|
|
968
|
+
_this._nodeCache.set(cacheId, res);
|
|
969
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
970
|
+
// console.log('Cache1: ' + 'Create - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
956
971
|
var serverRes = {
|
|
957
972
|
messageId: messageId,
|
|
958
973
|
hasError: false,
|
|
@@ -1006,8 +1021,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1006
1021
|
var serverRes = {
|
|
1007
1022
|
messageId: client.messageId,
|
|
1008
1023
|
hasError: false,
|
|
1009
|
-
data: _this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].
|
|
1024
|
+
data: _this._nodeCache.get(_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id)
|
|
1010
1025
|
};
|
|
1026
|
+
// console.log('Cache: ' + 'Found - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1011
1027
|
_this.sendWS(ws, serverRes);
|
|
1012
1028
|
}
|
|
1013
1029
|
});
|
|
@@ -1018,19 +1034,23 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1018
1034
|
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
1019
1035
|
}
|
|
1020
1036
|
(_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
|
|
1021
|
-
|
|
1022
|
-
|
|
1037
|
+
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
1038
|
+
if (nodeCacheSize > 500000000) {
|
|
1023
1039
|
var neededSizeIndex = 0;
|
|
1024
1040
|
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1041
|
+
_this._nodeCache.del(_this._subCache[zz].id);
|
|
1042
|
+
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
1043
|
+
neededSizeIndex = zz;
|
|
1028
1044
|
break;
|
|
1029
1045
|
}
|
|
1030
1046
|
}
|
|
1047
|
+
// console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1031
1048
|
_this._subCache.splice(0, neededSizeIndex);
|
|
1032
1049
|
}
|
|
1033
|
-
|
|
1050
|
+
var cacheId = _this._cacheId++;
|
|
1051
|
+
_this._nodeCache.set(cacheId, res);
|
|
1052
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
1053
|
+
// console.log('Cache: ' + 'Create - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1034
1054
|
subscription.clients.forEach(function (client) {
|
|
1035
1055
|
that._wss.clients.forEach(function (ws) {
|
|
1036
1056
|
if (ws['id_socket'] === client.id_socket) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolveio/server-lib",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.13-newrole",
|
|
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",
|