From 10527bf9b81ccbffc57925faa0df5d9361ee9dfc Mon Sep 17 00:00:00 2001 From: wang-liang0615 <53748875+wang-liang0615@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:33:25 +0800 Subject: [PATCH] pref(cmdb-ui):ci upload&delete concurrent 6 (#286) --- .../cmdb/views/batch/modules/UploadResult.vue | 25 +++++++++++-------- cmdb-ui/src/modules/cmdb/views/ci/index.vue | 20 +++++++++------ .../modules/cmdb/views/tree_views/index.vue | 20 +++++++++------ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/cmdb-ui/src/modules/cmdb/views/batch/modules/UploadResult.vue b/cmdb-ui/src/modules/cmdb/views/batch/modules/UploadResult.vue index c3813dd..eee7409 100644 --- a/cmdb-ui/src/modules/cmdb/views/batch/modules/UploadResult.vue +++ b/cmdb-ui/src/modules/cmdb/views/batch/modules/UploadResult.vue @@ -63,20 +63,23 @@ export default { this.success = 0 this.errorNum = 0 this.errorItems = [] - for (let i = 0; i < this.total; i++) { - // await this.sleep(20) - const item = this.upLoadData[i] - await uploadData(this.ciType, item) + const floor = Math.ceil(this.total / 6) + for (let i = 0; i < floor; i++) { + const itemList = this.upLoadData.slice(6 * i, 6 * i + 6) + const promises = itemList.map((x) => uploadData(this.ciType, x)) + await Promise.allSettled(promises) .then((res) => { - console.log(res) - this.success += 1 - }) - .catch((err) => { - this.errorNum += 1 - this.errorItems.push(((err.response || {}).data || {}).message || '请求出现错误,请稍后再试') + res.forEach((r) => { + if (r.status === 'fulfilled') { + this.success += 1 + } else { + this.errorItems.push(r?.reason?.response?.data.message ?? '请求出现错误,请稍后再试') + this.errorNum += 1 + } + }) }) .finally(() => { - this.complete += 1 + this.complete += 6 }) } }, diff --git a/cmdb-ui/src/modules/cmdb/views/ci/index.vue b/cmdb-ui/src/modules/cmdb/views/ci/index.vue index 0b543fa..ac9700f 100644 --- a/cmdb-ui/src/modules/cmdb/views/ci/index.vue +++ b/cmdb-ui/src/modules/cmdb/views/ci/index.vue @@ -654,13 +654,19 @@ export default { let errorNum = 0 this.loading = true this.loadTip = `正在删除...` - for (let i = 0; i < this.selectedRowKeys.length; i++) { - await deleteCI(this.selectedRowKeys[i], false) - .then(() => { - successNum += 1 - }) - .catch(() => { - errorNum += 1 + const floor = Math.ceil(this.selectedRowKeys.length / 6) + for (let i = 0; i < floor; i++) { + const itemList = this.selectedRowKeys.slice(6 * i, 6 * i + 6) + const promises = itemList.map((x) => deleteCI(x, false)) + await Promise.allSettled(promises) + .then((res) => { + res.forEach((r) => { + if (r.status === 'fulfilled') { + successNum += 1 + } else { + errorNum += 1 + } + }) }) .finally(() => { this.loadTip = `正在删除,共${this.selectedRowKeys.length}个,成功${successNum}个,失败${errorNum}个` diff --git a/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue b/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue index 374fe22..5c105ed 100644 --- a/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue +++ b/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue @@ -1084,13 +1084,19 @@ export default { let errorNum = 0 this.loading = true this.loadTip = `正在删除...` - for (let i = 0; i < this.selectedRowKeys.length; i++) { - await deleteCI(this.selectedRowKeys[i], false) - .then(() => { - successNum += 1 - }) - .catch(() => { - errorNum += 1 + const floor = Math.ceil(this.selectedRowKeys.length / 6) + for (let i = 0; i < floor; i++) { + const itemList = this.selectedRowKeys.slice(6 * i, 6 * i + 6) + const promises = itemList.map((x) => deleteCI(x, false)) + await Promise.allSettled(promises) + .then((res) => { + res.forEach((r) => { + if (r.status === 'fulfilled') { + successNum += 1 + } else { + errorNum += 1 + } + }) }) .finally(() => { this.loadTip = `正在删除,共${this.selectedRowKeys.length}个,成功${successNum}个,失败${errorNum}个`