From b0630005d923b495708547e913c90d4e8aa5bb59 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Thu, 24 Aug 2023 10:30:04 +0800 Subject: [PATCH] fix: swagger block event loop --- .../plugins/api-doc/src/server/swagger/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/plugins/api-doc/src/server/swagger/index.ts b/packages/plugins/api-doc/src/server/swagger/index.ts index 39cb587e1..d4f55f22a 100644 --- a/packages/plugins/api-doc/src/server/swagger/index.ts +++ b/packages/plugins/api-doc/src/server/swagger/index.ts @@ -32,18 +32,21 @@ export class SwaggerManager { return this.generateSwagger(); } - collection2Swagger(collectionName: string, withAssociation = true) { + async collection2Swagger(collectionName: string, withAssociation = true) { const collection = this.db.getCollection(collectionName); - return collectionToSwaggerObject(collection, { - withAssociation, - }); + return await (async () => { + await new Promise((resolve) => setTimeout(resolve, 0)); + return collectionToSwaggerObject(collection, { + withAssociation, + }); + })(); } async getCollectionsSwagger(name?: string) { const base = await this.getBaseSwagger(); let others = {}; if (name) { - const collectionSwagger = this.collection2Swagger(name); + const collectionSwagger = await this.collection2Swagger(name); others = merge(others, collectionSwagger); } else { const collections = await this.db.getRepository('collections').find({ @@ -59,7 +62,7 @@ export class SwaggerManager { } try { - others = merge(others, this.collection2Swagger(collection.name, false)); + others = merge(others, await this.collection2Swagger(collection.name, false)); } catch (e) { this.app.log.error(e); }