From df3ba133c73a0f444f7b11bd9c6b03efceb3ae8e Mon Sep 17 00:00:00 2001 From: GALENS <260827400@qq.com> Date: Thu, 7 Apr 2022 23:19:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=A4=9A=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E5=8F=91=E4=BB=B6=E5=A4=B1=E8=B4=A5=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/Server/Http/Modules/SendEmail/SendTask.cs | 2 +- .../Server/Http/Modules/SendEmail/SendThread.cs | 15 ++++++++++++--- UI/src/views/send/components/historyDetail.vue | 9 ++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Server/Server/Http/Modules/SendEmail/SendTask.cs b/Server/Server/Http/Modules/SendEmail/SendTask.cs index b93a69b1..611fba45 100644 --- a/Server/Server/Http/Modules/SendEmail/SendTask.cs +++ b/Server/Server/Http/Modules/SendEmail/SendTask.cs @@ -227,7 +227,7 @@ private void SendItems(List sendItemList) }); // 开始运行 - Task.WhenAll(sendThreads.ConvertAll(st => st.Run(sendItemStack))).ContinueWith((task) => + Task.WhenAll(sendThreads.ConvertAll(st => st.Run(sendItemStack,sendItemList))).ContinueWith((task) => { // 执行回调 // 发送关闭命令 diff --git a/Server/Server/Http/Modules/SendEmail/SendThread.cs b/Server/Server/Http/Modules/SendEmail/SendThread.cs index be86b6c0..1d5deb6e 100644 --- a/Server/Server/Http/Modules/SendEmail/SendThread.cs +++ b/Server/Server/Http/Modules/SendEmail/SendThread.cs @@ -60,13 +60,18 @@ public SendThread(string userId, SendBox sendBox, LiteDBManager liteDb) } - // 开始发件 - public Task Run(Stack sendItems) + /// + /// 开始发件 + /// + /// 不同进程共享的栈 + /// 原始发件数据,只有成功后才移除,当数量为 0 时,所有的进程退出 + /// + public Task Run(Stack sendItems, List sendItemsList) { // 创建线程 Task task = Task.Run(async () => { - while (sendItems.Count > 0) + while (sendItemsList.Count > 0) { // 开始并行发送 //确定smtp服务器地址 实例化一个Smtp客户端 @@ -92,6 +97,10 @@ public Task Run(Stack sendItems) //发送邮件 smtpclient.Send(mailMessage); + // 发送成功后,马上从原始数据中移除 + var index = sendItemsList.FindIndex(item => item._id == sendItem._id); + if (index > -1) sendItemsList.RemoveAt(index); + // 发送成功后,更新数据,更新到数据库 sendItem.senderEmail = _sendBox.email; sendItem.senderName = _sendBox.userName; diff --git a/UI/src/views/send/components/historyDetail.vue b/UI/src/views/send/components/historyDetail.vue index ed0371cb..c3b02b5d 100644 --- a/UI/src/views/send/components/historyDetail.vue +++ b/UI/src/views/send/components/historyDetail.vue @@ -207,8 +207,9 @@ export default { computed: { // 是否显示重新发送功能 isShowResent() { - const needResend = this.data.filter(d => !d.isSent) - return needResend.length > 0 + const result = this.data.some(d => !d.isSent) + console.log('isShowResent:', result) + return result }, resentClass() { @@ -220,7 +221,7 @@ export default { watch: { data(val) { - this.disableResend = val.some(d => !d.isSent) + this.disableResend = val.every(d => d.isSent) } }, @@ -276,7 +277,6 @@ export default { // 关闭重发,关闭取消 this.disableResend = true - this.isResending = true this.disableCancle = true this.getProgressInfo() @@ -308,7 +308,6 @@ export default { this.initQuasarTable_onRequest() // 打开按钮锁定 - this.disableResend = needResend.length < 1 this.disableCancle = false this.isResending = false // 恢复重发初始值