From 92bd0f6be3a139d9a17521cac2abe55847a0770f Mon Sep 17 00:00:00 2001 From: "1519715742@qq.com" <1519715742@qq.com> Date: Tue, 4 Feb 2020 19:12:44 +0800 Subject: [PATCH] Performance improvement in multiple files --- src/App.vue | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 079d7c2..158ff29 100644 --- a/src/App.vue +++ b/src/App.vue @@ -96,6 +96,19 @@ tableData: [], playing_url: "", playing_auto: false, + workCount: 0, + cacheQueue: [], + cacheQueueOption: { + push: (element) => { + this.cacheQueue.push(element); + }, + pop: () => { + return this.cacheQueue.shift(); + }, + size: () => { + return this.cacheQueue.length; + } + }, } }, mounted() { @@ -117,9 +130,43 @@ }); }, handleFile(file) { - + // 新的文件加入 + if (file) { + console.log("workCount", this.workCount); + // 将工作数量大小限制为100 + if (this.workCount < 100) { + // 工作数量增加 + this.workCount++; + // 工作数量小于100 立刻处理文件 + this.handleDoFile(file); + } + // 工作数量大于100 则放入缓存队列 + else { + this.cacheQueueOption.push(file); + } + } + //消费缓存队列的数据 + else { + this.workCount++; + this.handleDoFile(this.cacheQueueOption.pop()); + } + }, + handleCacheQueue() { + // 缓存队列中有数据且工作数量少于50的话 调用方法消费缓存队列中的数据 + if (this.cacheQueueOption.size() > 0 && this.workCount < 50) { + this.handleFile(null); + console.log("size", this.cacheQueueOption.size(), this.workCount); + } + }, + handleDoFile(file) { (async () => { let data = await dec.CommonDecrypt(file); + + + // 完成之后 数量减少 同时调用判断函数 + this.workCount--; + this.handleCacheQueue(); + if (data.status) { this.tableData.push(data); this.$notify.success({