nodebb-plugin-dbsearch 6.2.12 → 6.2.14

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-dbsearch",
3
- "version": "6.2.12",
3
+ "version": "6.2.14",
4
4
  "description": "A Plugin that lets users search posts and topics",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -14,21 +14,23 @@ module.exports = {
14
14
  // redis is not affected, since everything is string already
15
15
  return;
16
16
  }
17
-
17
+ const batch = require.main.require('./src/batch');
18
18
  async function convertIdToString(collection, docs) {
19
- for (const doc of docs) {
20
- if (doc._id) {
21
- const stringId = doc._id.toString();
22
- // eslint-disable-next-line no-await-in-loop
23
- await db.client.collection(collection).deleteOne({ _id: doc._id });
24
- // eslint-disable-next-line no-await-in-loop
25
- await db.client.collection(collection).insertOne({
26
- ...doc,
27
- _id: stringId,
28
- });
29
- }
30
- progress.incr(1);
31
- }
19
+ await batch.processArray(docs, async (docs) => {
20
+ await db.client.collection(collection).deleteMany({
21
+ _id: { $in: docs.map(doc => doc._id) },
22
+ });
23
+
24
+ const bulk = db.client.collection(collection).initializeUnorderedBulkOp();
25
+ docs.forEach(doc => bulk.insertOne({
26
+ ...doc,
27
+ _id: doc._id.toString(),
28
+ }));
29
+ await bulk.execute();
30
+ }, {
31
+ batch: 500,
32
+ });
33
+ progress.incr(docs.length);
32
34
  }
33
35
 
34
36
  if (mainDB === 'mongo') {
@@ -37,7 +37,7 @@ module.exports = {
37
37
  await db.client.collection('searchtopic').createIndex({ ts: 1 }, { });
38
38
  await db.client.collection('searchpost').createIndex({ ts: 1 }, { });
39
39
 
40
- const projection = { _id: 1, cid: 0, uid: 0, content: 0 };
40
+ const projection = { _id: 1 };
41
41
  const topics = await db.client.collection('searchtopic').find({}, { projection }).toArray();
42
42
  const posts = await db.client.collection('searchpost').find({}, { projection }).toArray();
43
43