Merge pull request #75 from overleaf/spd-p-map

Replace tiny-async-pool with p-map
This commit is contained in:
Simon Detheridge 2020-09-17 15:37:37 +01:00 committed by GitHub
commit 9ec93ca0d6
3 changed files with 34 additions and 19 deletions

View file

@ -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
})
}
}

View file

@ -1403,6 +1403,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",
@ -1909,6 +1918,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",
@ -3640,8 +3654,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",
@ -4843,6 +4856,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",

View file

@ -26,9 +26,9 @@
"express": "^4.17.1",
"logger-sharelatex": "^2.2.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": {