diff --git a/workers/queue.ts b/workers/queue.ts index dfae0d3644..4247cea3fb 100644 --- a/workers/queue.ts +++ b/workers/queue.ts @@ -11,7 +11,7 @@ import { WorkerTask } from 'server/models'; import { expect } from 'utils/assert'; import { createCachePurgeDebouncer } from 'utils/caching/createCachePurgeDebouncer'; -const maxWorkerTimeSeconds = 120; +const maxWorkerTimeSeconds = 300; const maxWorkerThreads = 5; let currentWorkerThreads = 0; diff --git a/workers/tasks/import/metadata.ts b/workers/tasks/import/metadata.ts index 7f7270a566..ad6f87b558 100644 --- a/workers/tasks/import/metadata.ts +++ b/workers/tasks/import/metadata.ts @@ -3,6 +3,7 @@ import { metaValueToString, metaValueToJsonSerializable } from '@pubpub/prosemir import { getSearchUsers } from 'server/search/queries'; import { isValidDate } from 'utils/dates'; +import { asyncMap } from 'utils/async'; import { Falsy } from 'types'; const getAuthorsArray = (author) => { @@ -23,18 +24,23 @@ const getDateStringFromMetaValue = (metaDateString) => { return null; }; +const getAuthorEntries = async (authorEntry) => { + if (typeof authorEntry === 'string') { + const users = await getSearchUsers(authorEntry); + return { name: authorEntry, users: users.map((user) => user.toJSON()) }; + } + return authorEntry; +}; const getAttributions = async (author) => { if (author) { const authorsArray = getAuthorsArray(author); const authorEntries = authorsArray.map(metaValueToJsonSerializable) as any[]; - const attributions = await Promise.all( - authorEntries.map(async (authorEntry: string) => { - if (typeof authorEntry === 'string') { - const users = await getSearchUsers(authorEntry); - return { name: authorEntry, users: users.map((user) => user.toJSON()) }; - } - return authorEntry; - }), + const attributions = await asyncMap( + authorEntries, + (authorEntry) => getAuthorEntries(authorEntry), + { + concurrency: 2, + }, ); return attributions; }