nodebb-plugin-dbsearch 6.2.11 → 6.2.12
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
CHANGED
|
@@ -9,39 +9,37 @@ module.exports = {
|
|
|
9
9
|
method: async function () {
|
|
10
10
|
const { progress } = this;
|
|
11
11
|
const nconf = require.main.require('nconf');
|
|
12
|
+
const batch = require.main.require('./src/batch');
|
|
12
13
|
const isMongo = nconf.get('database') === 'mongo';
|
|
13
14
|
if (!isMongo) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
async function addTsField(collection, docs) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} else if (collection === 'searchpost') {
|
|
26
|
-
// eslint-disable-next-line no-await-in-loop
|
|
27
|
-
ts = await db.getObjectField(`post:${stringId}`, 'timestamp');
|
|
28
|
-
}
|
|
29
|
-
ts = parseInt(ts, 10);
|
|
30
|
-
if (ts) {
|
|
31
|
-
// eslint-disable-next-line no-await-in-loop
|
|
32
|
-
await db.client.collection(collection).updateOne({
|
|
33
|
-
_id: stringId,
|
|
34
|
-
}, { $set: { ts } });
|
|
35
|
-
}
|
|
19
|
+
await batch.processArray(docs, async (docData) => {
|
|
20
|
+
const ids = docData.map(d => d._id);
|
|
21
|
+
let itemData = [];
|
|
22
|
+
if (collection === 'searchtopic') {
|
|
23
|
+
itemData = await db.getObjectsFields(ids.map(id => `topic:${id}`), ['timestamp']);
|
|
24
|
+
} else if (collection === 'searchpost') {
|
|
25
|
+
itemData = await db.getObjectsFields(ids.map(id => `post:${id}`), ['timestamp']);
|
|
36
26
|
}
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const bulk = db.client.collection(collection).initializeUnorderedBulkOp();
|
|
28
|
+
ids.forEach(
|
|
29
|
+
(id, index) => bulk.find({ _id: id }).updateOne({ $set: { ts: itemData[index].timestamp } })
|
|
30
|
+
);
|
|
31
|
+
await bulk.execute();
|
|
32
|
+
progress.incr(docData.length);
|
|
33
|
+
}, {
|
|
34
|
+
batch: 500,
|
|
35
|
+
});
|
|
39
36
|
}
|
|
40
37
|
await db.client.collection('searchtopic').createIndex({ ts: 1 }, { });
|
|
41
38
|
await db.client.collection('searchpost').createIndex({ ts: 1 }, { });
|
|
42
39
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
40
|
+
const projection = { _id: 1, cid: 0, uid: 0, content: 0 };
|
|
41
|
+
const topics = await db.client.collection('searchtopic').find({}, { projection }).toArray();
|
|
42
|
+
const posts = await db.client.collection('searchpost').find({}, { projection }).toArray();
|
|
45
43
|
|
|
46
44
|
progress.total = topics.length + posts.length;
|
|
47
45
|
|