Skip to content

Conversation

@winddies
Copy link
Contributor

  • 解决demo页面因更新chunk进度导致的卡顿问题
  • 加入分片上传请求的并发控制
  • 加入单元测试
README.md Outdated
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次);**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
* config.thread: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
* config.md5: md5 校验,为布尔值,默认 `false`;为 `true` 时,会对分片进行 md5 校验,在断点续传时,若分片 md5 值与断点储存的 md5 不一致,则重传文件。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解释一下为什么默认是 false

package.json Outdated
"name": "qiniu-js",
"jsName": "qiniu",
"version": "2.1.3",
"version": "2.1.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.2.0

src/pool.js Outdated
insertQueue(task){
return new Promise((resolve, reject) => {
this.queue.push({
...task,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 task 里有个字段 resolve,这里就有问题了吧;这边不用把 task 展开的,直接拿 { task, resolve, reject } 作为一个 item 就好了

src/pool.js Outdated
toDo(){
let onDoingNum = this.onDoing.length;
let availableNum = this.limit - onDoingNum;
this.onDoing.forEach(task => this.queue = this.queue.filter(item => item !== task));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这事儿为什么在这做啊,为什么不是放在 start 里,this.onDoing.push(task); 之后做?不然在这两行代码运行的间隔里,数据处于一个不一致/合法的状态(onDoing 里跟 queue 里都有)

src/pool.js Outdated
constructor(doTask, limit) {
this.doTask = doTask;
this.queue = [];
this.onDoing = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么是 onDoing,一般 onFoo 这种命名不都是表示这是个处理 foo 事件的 handler 嘛?

src/upload.js Outdated
}
if (err.code === 599 && ++this.retryCount < this.config.retryCount) {

if (err.code === 0 && !this.abort){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应对 599?注释说明

src/upload.js Outdated
if (err.code === 599 && ++this.retryCount < this.config.retryCount) {

if (err.code === 0 && !this.abort){
if (--this.config.retryCount >= 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

维护 this.tryCount

src/upload.js Outdated
}
}

if (err.code === 701 || (err.message && err.message === "md5不一致")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

701 是啥,注释说明下?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

外面不需要接触 md5 的逻辑

src/pool.js Outdated
this.abort = false;
}

insertQueue(task){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insertQueue -> enqueue
start -> run
doTask -> runTask
todo -> check?

README.md Outdated
* config.disableStatisticsReport: 是否禁用日志报告,为布尔值,默认为 `false`
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次);**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
* config.thread: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pool 那边改成 limit 了,这边就改成 concurrentRequestLimit

README.md Outdated
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次);**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
* config.thread: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
* config.md5: md5 校验,为布尔值;在断点续传时,开启md5校验会对已上传的也进行md5计算比对,所以会增加上传时间,默认 `false`;为 `true` 时,会对分片进行 md5 校验,在断点续传时,若分片 md5 值与断点储存的 md5 不一致,则重传该分片。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

md5 -> checkByMD5?

src/upload.js Outdated
this.progress = null;
this.xhrList = [];
this.xhrHandler = xhr => this.xhrList.push(xhr);
this.abort = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abort -> aborted

README.md Outdated
* config.disableStatisticsReport: 是否禁用日志报告,为布尔值,默认为 `false`
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次);**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
* config.currentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是 current,是 concurrent...

src/upload.js Outdated
}

let needRetry = err.isRequestError && err.code === 0 && !this.aborted;
let reachRetryCount = ++this.retryCount <= this.config.retryCount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个明显是 have not reached retry count 啊...

}
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空格

src/upload.js Outdated
removeLocalFileInfo(this.file);
},
err => {
// ctx错误或者过期情况下,或者md5不匹配时,清除本地存储数据
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“或者md5不匹配”?

README.md Outdated
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次);**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
* config.currentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
* config.checkByMD5: md5 校验,为布尔值;在断点续传时,开启 md5 校验会对已上传的进行 md5 计算比对,防止文件被修改,若分片 md5 值与断点储存的 md5 不一致,则重传该分片,所以会增加上传时间,默认 `false`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • config.checkByMD5: 是否开启 MD5 校验,为布尔值;在断点续传时,开启 MD5 校验会将已上传的分片与当前分片进行 MD5 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 MD5 需要花费一定的时间,因此会稍微增加断点续传时的耗时。默认为 false,不开启。
Copy link
Contributor

@nighca nighca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚗

@nighca nighca merged commit 02638c2 into qiniu:master Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants