mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-13 19:23:42 +08:00
Give raw-material uploads a dedicated five-minute timeout and process file-picker and drag/drop uploads through a shared two-worker queue, so constrained uplinks no longer abort multipart requests at the global 30-second deadline. Switch wiki processing jobs and page citations to application-assigned IDs: the PostgreSQL/Kingbase migrations define plain BIGINT primary keys without identity defaults, so database-generated keys fail on insert.
24 lines
700 B
TypeScript
24 lines
700 B
TypeScript
export const WIKI_UPLOAD_TIMEOUT_MS = 5 * 60 * 1000
|
|
|
|
export const WIKI_UPLOAD_CONCURRENCY = 2
|
|
|
|
export async function processWithConcurrency<T>(
|
|
items: readonly T[],
|
|
worker: (item: T, index: number) => Promise<void>,
|
|
concurrency = WIKI_UPLOAD_CONCURRENCY,
|
|
): Promise<void> {
|
|
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
throw new RangeError('concurrency must be a positive integer')
|
|
}
|
|
|
|
const iterator = items.entries()
|
|
async function runWorker() {
|
|
for (const [index, item] of iterator) {
|
|
await worker(item, index)
|
|
}
|
|
}
|
|
|
|
const workerCount = Math.min(concurrency, items.length)
|
|
await Promise.all(Array.from({ length: workerCount }, () => runWorker()))
|
|
}
|