wingbot-mongodb 3.2.1 → 3.2.3
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.
- package/.nyc_output/8db620e2-5deb-4db5-b239-32d4e6eb824a.json +1 -0
- package/.nyc_output/processinfo/8db620e2-5deb-4db5-b239-32d4e6eb824a.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +1 -1
- package/src/BaseStorage.js +45 -14
- package/src/NotificationsStorage.js +22 -13
- package/.nyc_output/6a7ed916-683a-43fd-8624-795a77e80a4a.json +0 -1
- package/.nyc_output/processinfo/6a7ed916-683a-43fd-8624-795a77e80a4a.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":4692,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1681800952490,"ppid":4686,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/8db620e2-5deb-4db5-b239-32d4e6eb824a.json","externalId":"","uuid":"8db620e2-5deb-4db5-b239-32d4e6eb824a","files":["/Users/david/Development/wingbot-mongodb/src/BaseStorage.js","/Users/david/Development/wingbot-mongodb/src/defaultLogger.js","/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js","/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js","/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js","/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js","/Users/david/Development/wingbot-mongodb/src/tokenFactory.js","/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js","/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js","/Users/david/Development/wingbot-mongodb/src/StateStorage.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"8db620e2-5deb-4db5-b239-32d4e6eb824a":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"]},"externalIds":{}}
|
package/package.json
CHANGED
package/src/BaseStorage.js
CHANGED
|
@@ -270,6 +270,12 @@ class BaseStorage {
|
|
|
270
270
|
return this._collection;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
+
/**
|
|
274
|
+
*
|
|
275
|
+
* @param {object[]} indexes
|
|
276
|
+
* @param {Collection} collection
|
|
277
|
+
* @returns {Promise}
|
|
278
|
+
*/
|
|
273
279
|
async _ensureIndexes (indexes, collection) {
|
|
274
280
|
let existing;
|
|
275
281
|
try {
|
|
@@ -290,7 +296,7 @@ class BaseStorage {
|
|
|
290
296
|
});
|
|
291
297
|
}, Promise.resolve());
|
|
292
298
|
|
|
293
|
-
|
|
299
|
+
let updated = await indexes
|
|
294
300
|
.filter((i) => !existing.some((e) => e.name === i.options.name))
|
|
295
301
|
.reduce((p, i) => {
|
|
296
302
|
this._log.log(`DB.${this._collectionName} creating index ${i.options.name}`);
|
|
@@ -302,21 +308,46 @@ class BaseStorage {
|
|
|
302
308
|
.then(() => true);
|
|
303
309
|
}, Promise.resolve(false));
|
|
304
310
|
|
|
305
|
-
if (updated
|
|
306
|
-
|
|
311
|
+
if (!updated) {
|
|
312
|
+
updated = existing.every((i) => this.systemIndexes.includes(i.name));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let fixtures = this._fixtures;
|
|
316
|
+
|
|
317
|
+
const $in = fixtures
|
|
318
|
+
.map((f) => f._id)
|
|
319
|
+
.filter((f) => !!f);
|
|
320
|
+
|
|
321
|
+
if (!updated && $in.length !== 0) {
|
|
322
|
+
const found = await collection
|
|
323
|
+
.find({ _id: { $in } })
|
|
324
|
+
.project({ _id: 1 })
|
|
325
|
+
.map((doc) => doc._id.toString())
|
|
326
|
+
.toArray();
|
|
327
|
+
|
|
328
|
+
if (found.length !== $in.length) {
|
|
329
|
+
updated = true;
|
|
330
|
+
fixtures = fixtures
|
|
331
|
+
.filter((f) => !f._id || !found.includes(f._id.toString()));
|
|
332
|
+
}
|
|
307
333
|
|
|
308
|
-
await this._fixtures.reduce(
|
|
309
|
-
(p, o) => p
|
|
310
|
-
.then(() => collection.insertOne(o))
|
|
311
|
-
.then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
|
|
312
|
-
.catch((e) => {
|
|
313
|
-
if (e.code !== 11000) {
|
|
314
|
-
this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
|
|
315
|
-
}
|
|
316
|
-
}),
|
|
317
|
-
Promise.resolve()
|
|
318
|
-
);
|
|
319
334
|
}
|
|
335
|
+
|
|
336
|
+
if (!updated || fixtures.length === 0) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
await fixtures.reduce(
|
|
341
|
+
(p, o) => p
|
|
342
|
+
.then(() => collection.insertOne(o))
|
|
343
|
+
.then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
|
|
344
|
+
.catch((e) => {
|
|
345
|
+
if (e.code !== 11000) {
|
|
346
|
+
this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
|
|
347
|
+
}
|
|
348
|
+
}),
|
|
349
|
+
Promise.resolve()
|
|
350
|
+
);
|
|
320
351
|
}
|
|
321
352
|
|
|
322
353
|
/**
|
|
@@ -303,13 +303,14 @@ class NotificationsStorage {
|
|
|
303
303
|
|
|
304
304
|
const findMissingIds = tasks
|
|
305
305
|
.reduce((arr, {
|
|
306
|
-
campaignId, senderId, pageId, sent
|
|
306
|
+
campaignId, senderId, pageId, sent, enqueue
|
|
307
307
|
}, i) => {
|
|
308
308
|
if (typeof res.upsertedIds[i] !== 'undefined') {
|
|
309
309
|
return arr;
|
|
310
310
|
}
|
|
311
311
|
arr.push({
|
|
312
312
|
i,
|
|
313
|
+
enqueue,
|
|
313
314
|
filter: {
|
|
314
315
|
campaignId, senderId, pageId, sent
|
|
315
316
|
}
|
|
@@ -321,23 +322,31 @@ class NotificationsStorage {
|
|
|
321
322
|
|
|
322
323
|
if (findMissingIds.length > 0) {
|
|
323
324
|
await Promise.all(findMissingIds
|
|
324
|
-
.map(({ filter, i }) => c.findOne(filter, {
|
|
325
|
+
.map(({ filter, i, enqueue }) => c.findOne(filter, {
|
|
325
326
|
projection: {
|
|
326
327
|
_id: 1, insEnqueue: 1, enqueue: 1, ups: 1
|
|
327
328
|
}
|
|
328
329
|
})
|
|
329
330
|
.then((found) => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
? found.
|
|
339
|
-
: found.
|
|
340
|
-
|
|
331
|
+
if (!found) { // race condition occurred
|
|
332
|
+
missingIds.set(i, {
|
|
333
|
+
id: null,
|
|
334
|
+
insEnqueue: -1,
|
|
335
|
+
enqueue
|
|
336
|
+
});
|
|
337
|
+
} else {
|
|
338
|
+
const id = typeof found._id === 'string'
|
|
339
|
+
? found._id
|
|
340
|
+
: found._id.toHexString();
|
|
341
|
+
missingIds.set(i, {
|
|
342
|
+
id,
|
|
343
|
+
insEnqueue: found.insEnqueue,
|
|
344
|
+
enqueue: found.insEnqueue === found.enqueue
|
|
345
|
+
&& found.enqueue !== MAX_TS && found.ups !== 1
|
|
346
|
+
? found.enqueue + 1
|
|
347
|
+
: found.enqueue
|
|
348
|
+
});
|
|
349
|
+
}
|
|
341
350
|
})));
|
|
342
351
|
}
|
|
343
352
|
|