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 Streamifier = require('streamifier')
const RangeManager = require('./RangeManager') const RangeManager = require('./RangeManager')
const PersistorManager = require('./PersistorManager') const PersistorManager = require('./PersistorManager')
const asyncPool = require('tiny-async-pool') const pMap = require('p-map')
const PARALLEL_JOBS = 5 const PARALLEL_JOBS = 5
@ -40,11 +40,9 @@ async function archiveAllDocs(projectId) {
} }
const docsToArchive = docs.filter((doc) => !doc.inS3) const docsToArchive = docs.filter((doc) => !doc.inS3)
if (docsToArchive.length) { await pMap(docsToArchive, (doc) => archiveDoc(projectId, doc), {
await asyncPool(PARALLEL_JOBS, docsToArchive, (doc) => concurrency: PARALLEL_JOBS
archiveDoc(projectId, doc) })
)
}
} }
async function archiveDoc(projectId, doc) { async function archiveDoc(projectId, doc) {
@ -85,13 +83,9 @@ async function unArchiveAllDocs(projectId) {
if (!docs) { if (!docs) {
throw new Errors.NotFoundError(`No docs for project ${projectId}`) throw new Errors.NotFoundError(`No docs for project ${projectId}`)
} }
if (!docs.length) { await pMap(docs, (doc) => unarchiveDoc(projectId, doc._id), {
// asyncPool will throw an error with an empty array concurrency: PARALLEL_JOBS
return })
}
await asyncPool(PARALLEL_JOBS, docs, (doc) =>
unarchiveDoc(projectId, doc._id)
)
} }
async function unarchiveDoc(projectId, docId) { async function unarchiveDoc(projectId, docId) {
@ -143,9 +137,9 @@ async function destroyAllDocs(projectId) {
{ _id: 1 } { _id: 1 }
) )
if (docs && docs.length) { if (docs && docs.length) {
await asyncPool(PARALLEL_JOBS, docs, (doc) => await pMap(docs, (doc) => destroyDoc(projectId, doc._id), {
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": { "ajv": {
"version": "6.10.0", "version": "6.10.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz",
@ -1909,6 +1918,11 @@
"readdirp": "~3.2.0" "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": { "cli-cursor": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@ -3640,8 +3654,7 @@
"indent-string": { "indent-string": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz",
"integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg=="
"dev": true
}, },
"inflight": { "inflight": {
"version": "1.0.6", "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": { "p-try": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",

View file

@ -26,9 +26,9 @@
"express": "^4.17.1", "express": "^4.17.1",
"logger-sharelatex": "^2.2.0", "logger-sharelatex": "^2.2.0",
"mongodb": "^3.6.0", "mongodb": "^3.6.0",
"p-map": "^4.0.0",
"settings-sharelatex": "^1.1.0", "settings-sharelatex": "^1.1.0",
"streamifier": "^0.1.1", "streamifier": "^0.1.1",
"tiny-async-pool": "^1.1.0",
"underscore": "~1.10.2" "underscore": "~1.10.2"
}, },
"devDependencies": { "devDependencies": {