wingbot-mongodb 4.2.3 → 4.2.4
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/package.json +1 -1
- package/src/StateStorage.js +25 -0
package/package.json
CHANGED
package/src/StateStorage.js
CHANGED
|
@@ -8,6 +8,9 @@ const defaultLogger = require('./defaultLogger');
|
|
|
8
8
|
|
|
9
9
|
const USER_INDEX = 'senderId_1_pageId_1';
|
|
10
10
|
const LAST_INTERACTION_INDEX = 'lastInteraction_1';
|
|
11
|
+
|
|
12
|
+
const COMPOUND_INDEX = 'senderId_1_pageId_1_lastInteraction_-1';
|
|
13
|
+
|
|
11
14
|
const SEARCH = 'search-text';
|
|
12
15
|
const NAME = 'name_1';
|
|
13
16
|
|
|
@@ -21,6 +24,8 @@ const NAME = 'name_1';
|
|
|
21
24
|
/**
|
|
22
25
|
* @typedef {object} StateCondition
|
|
23
26
|
* @prop {string} [search]
|
|
27
|
+
* @prop {string[]} [senderIds]
|
|
28
|
+
* @prop {string} [pageId]
|
|
24
29
|
*/
|
|
25
30
|
|
|
26
31
|
/** @typedef {import('mongodb').Db} Db */
|
|
@@ -59,6 +64,10 @@ class StateStorage extends BaseStorage {
|
|
|
59
64
|
{ name: NAME }
|
|
60
65
|
);
|
|
61
66
|
} else {
|
|
67
|
+
this.addIndex(
|
|
68
|
+
{ senderId: 1, pageId: 1, lastInteraction: -1 },
|
|
69
|
+
{ name: COMPOUND_INDEX, unique: true }
|
|
70
|
+
);
|
|
62
71
|
this.addIndex(
|
|
63
72
|
{ '$**': 'text' },
|
|
64
73
|
{ name: SEARCH }
|
|
@@ -201,6 +210,22 @@ class StateStorage extends BaseStorage {
|
|
|
201
210
|
|
|
202
211
|
const searchStates = typeof condition.search === 'string';
|
|
203
212
|
|
|
213
|
+
const filterSenderIds = Array.isArray(condition.senderIds);
|
|
214
|
+
|
|
215
|
+
const filterPageId = typeof condition.pageId === 'string';
|
|
216
|
+
|
|
217
|
+
if (filterSenderIds) {
|
|
218
|
+
Object.assign(useCondition, {
|
|
219
|
+
senderId: { $in: condition.senderIds }
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (filterPageId) {
|
|
224
|
+
Object.assign(useCondition, {
|
|
225
|
+
pageId: condition.pageId
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
204
229
|
if (searchStates) {
|
|
205
230
|
if (this._isCosmo) {
|
|
206
231
|
const $regex = `^${condition.search.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')}`;
|