diff --git a/services/docstore/app/js/DocArchiveManager.js b/services/docstore/app/js/DocArchiveManager.js index d564113c9b..126fbd6da0 100644 --- a/services/docstore/app/js/DocArchiveManager.js +++ b/services/docstore/app/js/DocArchiveManager.js @@ -7,7 +7,7 @@ const crypto = require('crypto') const Streamifier = require('streamifier') const RangeManager = require('./RangeManager') const PersistorManager = require('./PersistorManager') -const asyncPool = require('tiny-async-pool') +const pMap = require('p-map') const PARALLEL_JOBS = 5 @@ -40,11 +40,9 @@ async function archiveAllDocs(projectId) { } const docsToArchive = docs.filter((doc) => !doc.inS3) - if (docsToArchive.length) { - await asyncPool(PARALLEL_JOBS, docsToArchive, (doc) => - archiveDoc(projectId, doc) - ) - } + await pMap(docsToArchive, (doc) => archiveDoc(projectId, doc), { + concurrency: PARALLEL_JOBS + }) } async function archiveDoc(projectId, doc) { @@ -85,13 +83,9 @@ async function unArchiveAllDocs(projectId) { if (!docs) { throw new Errors.NotFoundError(`No docs for project ${projectId}`) } - if (!docs.length) { - // asyncPool will throw an error with an empty array - return - } - await asyncPool(PARALLEL_JOBS, docs, (doc) => - unarchiveDoc(projectId, doc._id) - ) + await pMap(docs, (doc) => unarchiveDoc(projectId, doc._id), { + concurrency: PARALLEL_JOBS + }) } async function unarchiveDoc(projectId, docId) { @@ -143,9 +137,9 @@ async function destroyAllDocs(projectId) { { _id: 1 } ) if (docs && docs.length) { - await asyncPool(PARALLEL_JOBS, docs, (doc) => - destroyDoc(projectId, doc._id) - ) + await pMap(docs, (doc) => destroyDoc(projectId, doc._id), { + concurrency: PARALLEL_JOBS + }) } } diff --git a/services/docstore/package-lock.json b/services/docstore/package-lock.json index 15faeeec6c..16ee117b07 100644 --- a/services/docstore/package-lock.json +++ b/services/docstore/package-lock.json @@ -1382,6 +1382,15 @@ } } }, + "aggregate-error": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", + "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", + "requires": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + } + }, "ajv": { "version": "6.10.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", @@ -1888,6 +1897,11 @@ "readdirp": "~3.2.0" } }, + "clean-stack": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", + "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==" + }, "cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -3603,8 +3617,7 @@ "indent-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", - "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", - "dev": true + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==" }, "inflight": { "version": "1.0.6", @@ -4837,6 +4850,14 @@ } } }, + "p-map": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz", + "integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==", + "requires": { + "aggregate-error": "^3.0.0" + } + }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", diff --git a/services/docstore/package.json b/services/docstore/package.json index 86b9a410fe..23392d5e67 100644 --- a/services/docstore/package.json +++ b/services/docstore/package.json @@ -26,9 +26,9 @@ "logger-sharelatex": "^2.2.0", "metrics-sharelatex": "^2.7.0", "mongodb": "^3.6.0", + "p-map": "^4.0.0", "settings-sharelatex": "^1.1.0", "streamifier": "^0.1.1", - "tiny-async-pool": "^1.1.0", "underscore": "~1.10.2" }, "devDependencies": {