@resolveio/server-lib 9.9.7 → 9.9.9

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.
@@ -14,6 +14,7 @@ interface MongoQueueModel {
14
14
  cbs_next: Function[];
15
15
  running: boolean;
16
16
  cacheId: number;
17
+ invalidateFlag: boolean;
17
18
  }
18
19
  export declare class MongoManager {
19
20
  private _collections;
@@ -85,6 +85,9 @@ var MongoManager = /** @class */ (function () {
85
85
  MongoManager.prototype.addToQueue = function (mongoQueue) {
86
86
  var _mongoQueue = this._mongoQueue.filter(function (a) { return a.name_collection === mongoQueue.name_collection && a.name_function === mongoQueue.name_function && a.name_function_addt === mongoQueue.name_function_addt && JSON.stringify(a.data_function) === JSON.stringify(mongoQueue.data_function) && JSON.stringify(a.data_function_addt) === JSON.stringify(mongoQueue.data_function_addt); })[0];
87
87
  if (_mongoQueue) {
88
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
89
+ console.log(new Date(), 'Add To queue - found queue', mongoQueue.running, mongoQueue.name_function, JSON.stringify(mongoQueue.data_function));
90
+ }
88
91
  if (!_mongoQueue.running) {
89
92
  _mongoQueue.cbs.push(mongoQueue.cbs[0]);
90
93
  }
@@ -93,6 +96,9 @@ var MongoManager = /** @class */ (function () {
93
96
  }
94
97
  }
95
98
  else {
99
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
100
+ console.log(new Date(), 'Add To queue - new queue', mongoQueue.name_function, JSON.stringify(mongoQueue.data_function));
101
+ }
96
102
  mongoQueue._id = this._mongoQueueId;
97
103
  this._mongoQueueId += 1;
98
104
  this._mongoQueue.splice(0, 0, mongoQueue);
@@ -111,6 +117,10 @@ var MongoManager = /** @class */ (function () {
111
117
  var _a, _b, _c;
112
118
  var mongoQueue = queueArr[i];
113
119
  mongoQueue.running = true;
120
+ mongoQueue.invalidateFlag = false;
121
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
122
+ console.log(new Date(), 'Add To queue - new queue', mongoQueue.name_function, JSON.stringify(mongoQueue.data_function));
123
+ }
114
124
  if (mongoQueue.cacheId) {
115
125
  var res_1 = JSON.parse(_this._nodeCache.get(mongoQueue.cacheId), common_1.dateReviver);
116
126
  mongoQueue.cbs.forEach(function (cb) {
@@ -118,16 +128,27 @@ var MongoManager = /** @class */ (function () {
118
128
  });
119
129
  mongoQueue.cbs = [];
120
130
  mongoQueue.running = false;
131
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
132
+ console.log(new Date(), 'Send Cache', mongoQueue.cacheId, mongoQueue.invalidateFlag, mongoQueue.running, mongoQueue.name_function, JSON.stringify(mongoQueue.data_function), mongoQueue.cbs_next.length);
133
+ }
121
134
  }
122
135
  else {
123
136
  if (!mongoQueue.name_function_addt) {
137
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
138
+ console.log(new Date(), 'Before Funct 1', mongoQueue.invalidateFlag, mongoQueue.running, mongoQueue.name_function, JSON.stringify(mongoQueue.data_function), mongoQueue.cbs_next.length);
139
+ }
124
140
  (_a = index_1.ResolveIOServer.getMainDB().collection(mongoQueue.name_collection))[mongoQueue.name_function].apply(_a, mongoQueue.data_function).then(function (res) {
125
- mongoQueue.cacheId = _this._mongoQueueCacheId;
126
- _this._mongoQueueCacheId += 1;
127
- _this.addToCache(mongoQueue.cacheId, res);
128
- mongoQueue.cbs.forEach(function (cb) {
129
- cb(null, res, false);
130
- });
141
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
142
+ console.log(new Date(), 'After Funct 1', mongoQueue.invalidateFlag, mongoQueue.running, mongoQueue.name_function, JSON.stringify(mongoQueue.data_function), mongoQueue.cbs_next.length);
143
+ }
144
+ if (!mongoQueue.invalidateFlag) {
145
+ mongoQueue.cacheId = _this._mongoQueueCacheId;
146
+ _this._mongoQueueCacheId += 1;
147
+ _this.addToCache(mongoQueue.cacheId, res);
148
+ mongoQueue.cbs.forEach(function (cb) {
149
+ cb(null, res, false);
150
+ });
151
+ }
131
152
  if (mongoQueue.cbs_next.length) {
132
153
  mongoQueue.cbs = mongoQueue.cbs_next;
133
154
  mongoQueue.cbs_next = [];
@@ -149,13 +170,21 @@ var MongoManager = /** @class */ (function () {
149
170
  });
150
171
  }
151
172
  else {
173
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
174
+ console.log(new Date(), 'Before Funct 2', mongoQueue.invalidateFlag, mongoQueue.running, mongoQueue.name_function, JSON.stringify(mongoQueue.data_function), mongoQueue.cbs_next.length);
175
+ }
152
176
  (_b = (_c = index_1.ResolveIOServer.getMainDB().collection(mongoQueue.name_collection))[mongoQueue.name_function].apply(_c, mongoQueue.data_function))[mongoQueue.name_function_addt].apply(_b, mongoQueue.data_function_addt).then(function (res) {
153
- mongoQueue.cacheId = _this._mongoQueueCacheId;
154
- _this._mongoQueueCacheId += 1;
155
- _this.addToCache(mongoQueue.cacheId, res);
156
- mongoQueue.cbs.forEach(function (cb) {
157
- cb(null, res, false);
158
- });
177
+ if (mongoQueue.name_collection !== 'logged-in-users' && mongoQueue.name_collection !== 'cron-jobs') {
178
+ console.log(new Date(), 'After Funct 2', mongoQueue.invalidateFlag, mongoQueue.running, mongoQueue.name_function, JSON.stringify(mongoQueue.data_function), mongoQueue.cbs_next.length);
179
+ }
180
+ if (!mongoQueue.invalidateFlag) {
181
+ mongoQueue.cacheId = _this._mongoQueueCacheId;
182
+ _this._mongoQueueCacheId += 1;
183
+ _this.addToCache(mongoQueue.cacheId, res);
184
+ mongoQueue.cbs.forEach(function (cb) {
185
+ cb(null, res, false);
186
+ });
187
+ }
159
188
  if (mongoQueue.cbs_next.length) {
160
189
  mongoQueue.cbs = mongoQueue.cbs_next;
161
190
  mongoQueue.cbs_next = [];
@@ -206,20 +235,25 @@ var MongoManager = /** @class */ (function () {
206
235
  if (nodeCacheSize < this._heapLimit * 0.75) {
207
236
  break;
208
237
  }
238
+ if (queue.name_collection !== 'logged-in-users' && queue.name_collection !== 'cron-jobs') {
239
+ console.log(new Date(), 'Deleting Cache', queue.running, queue.name_function, JSON.stringify(queue.data_function));
240
+ }
209
241
  }
210
242
  console.log('Query Cache: ' + 'Too Big, - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);
211
243
  }
244
+ console.log(new Date(), 'Add To Cache', JSON.stringify(data));
212
245
  this._nodeCache.set(id, JSON.stringify(data));
213
246
  };
214
247
  MongoManager.prototype.invalidateQueryCache = function (collection) {
215
248
  var queueArr = this._mongoQueue.filter(function (a) { return (a.name_collection === collection || a.lookup_collections.includes(collection)); });
216
249
  for (var i = queueArr.length - 1; i >= 0; i--) {
217
250
  var queue = queueArr[i];
218
- if (queue.name_collection !== 'logged-in-users' && queue.name_collection !== 'cron-jobs') {
219
- console.log(new Date(), 'Invalidate Query: ', queue.name_collection, queue.name_function, queue.data_function);
220
- }
221
251
  this._nodeCache.del(queue.cacheId);
222
252
  queue.cacheId = 0;
253
+ queue.invalidateFlag = true;
254
+ if (queue.name_collection !== 'logged-in-users' && queue.name_collection !== 'cron-jobs') {
255
+ console.log(new Date(), 'Invalidate query', queue.running, queue.name_function, JSON.stringify(queue.data_function));
256
+ }
223
257
  if (queue.running) {
224
258
  this.addToQueue(queue);
225
259
  }
@@ -322,7 +356,8 @@ var Collection = /** @class */ (function () {
322
356
  cacheId: 0,
323
357
  lookup_collections: pipeline.filter(function (a) { return a['$lookup'] && a['$lookup'].from; }).map(function (a) { return a['$lookup'].from; }).filter(function (elem, index, self) {
324
358
  return index === self.indexOf(elem);
325
- })
359
+ }),
360
+ invalidateFlag: false
326
361
  });
327
362
  }
328
363
  else {
@@ -353,7 +388,8 @@ var Collection = /** @class */ (function () {
353
388
  cacheId: 0,
354
389
  lookup_collections: pipeline.filter(function (a) { return a['$lookup'] && a['$lookup'].from; }).map(function (a) { return a['$lookup'].from; }).filter(function (elem, index, self) {
355
390
  return index === self.indexOf(elem);
356
- })
391
+ }),
392
+ invalidateFlag: false
357
393
  });
358
394
  });
359
395
  };
@@ -538,7 +574,8 @@ var Collection = /** @class */ (function () {
538
574
  cbs_next: [],
539
575
  running: false,
540
576
  cacheId: 0,
541
- lookup_collections: []
577
+ lookup_collections: [],
578
+ invalidateFlag: false
542
579
  });
543
580
  }
544
581
  else {
@@ -590,7 +627,8 @@ var Collection = /** @class */ (function () {
590
627
  cbs_next: [],
591
628
  running: false,
592
629
  cacheId: 0,
593
- lookup_collections: []
630
+ lookup_collections: [],
631
+ invalidateFlag: false
594
632
  });
595
633
  }
596
634
  else {