wingbot-mongodb 3.2.2 → 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/{98a862df-b2a1-4d14-9176-6b0bada108f7.json → 8db620e2-5deb-4db5-b239-32d4e6eb824a.json} +1 -1
- 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/.nyc_output/processinfo/98a862df-b2a1-4d14-9176-6b0bada108f7.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
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":81134,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1676533760202,"ppid":81133,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/98a862df-b2a1-4d14-9176-6b0bada108f7.json","externalId":"","uuid":"98a862df-b2a1-4d14-9176-6b0bada108f7","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"]}
|