diff --git a/packages/nocodb/src/utils/RequestQueue.ts b/packages/nocodb/src/utils/RequestQueue.ts new file mode 100644 index 0000000000..33bb639235 --- /dev/null +++ b/packages/nocodb/src/utils/RequestQueue.ts @@ -0,0 +1,41 @@ +export default class RequestQueue { + private runningCount: number; + private queue: any[]; + private maxParallelRequests: number; + + constructor(maxParallelRequests = 10) { + this.maxParallelRequests = maxParallelRequests; + this.queue = []; + this.runningCount = 0; + } + + async enqueue(requestFunction) { + return new Promise((resolve, reject) => { + const execute = async () => { + this.runningCount++; + try { + const result = await requestFunction(); + resolve(result); + } catch (error) { + reject(error); + } finally { + this.runningCount--; + this.processQueue(); + } + }; + + if (this.runningCount < this.maxParallelRequests) { + execute(); + } else { + this.queue.push(execute); + } + }); + } + + processQueue() { + if (this.runningCount < this.maxParallelRequests && this.queue.length > 0) { + const nextRequest = this.queue.shift(); + nextRequest(); + } + } +} diff --git a/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts b/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts index 50be6c17ab..ff71175d05 100644 --- a/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts +++ b/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts @@ -13,49 +13,7 @@ import ProjectMgrv2 from '~/db/sql-mgr/v2/ProjectMgrv2'; import { Altered } from '~/services/columns.service'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import getColumnUiType from '~/helpers/getColumnUiType'; - -// todo: move to utils -class RequestQueue { - private runningCount: number; - private queue: any[]; - private maxParallelRequests: number; - - constructor(maxParallelRequests = 10) { - this.maxParallelRequests = maxParallelRequests; - this.queue = []; - this.runningCount = 0; - } - - async enqueue(requestFunction) { - return new Promise((resolve, reject) => { - const execute = async () => { - this.runningCount++; - try { - const result = await requestFunction(); - resolve(result); - } catch (error) { - reject(error); - } finally { - this.runningCount--; - this.processQueue(); - } - }; - - if (this.runningCount < this.maxParallelRequests) { - execute(); - } else { - this.queue.push(execute); - } - }); - } - - processQueue() { - if (this.runningCount < this.maxParallelRequests && this.queue.length > 0) { - const nextRequest = this.queue.shift(); - nextRequest(); - } - } -} +import RequestQueue from '~/utils/RequestQueue'; // Example Usage: