Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't cache the intermediate locals for application #1146

Merged
merged 3 commits into from Jul 4, 2017
Merged

Conversation

JacksonTian
Copy link
Contributor

@JacksonTian JacksonTian commented Jul 3, 2017

Checklist
  • npm test passes
  • commit message follows commit guidelines
Affected core subsystem(s)

lib/application

Description of change

No more cache the intermediate locals for Application.

@mention-bot
Copy link

@JacksonTian, thanks for your PR! By analyzing the history of the files in this pull request, we identified @shaoshuai0102, @popomore and @fengmk2 to be potential reviewers.

@codecov
Copy link

codecov bot commented Jul 3, 2017

Codecov Report

Merging #1146 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1146      +/-   ##
=========================================
- Coverage    99.7%   99.7%   -0.01%     
=========================================
  Files          29      29              
  Lines         676     670       -6     
=========================================
- Hits          674     668       -6     
  Misses          2       2
Impacted Files Coverage Δ
lib/application.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7a87a8...1663cc8. Read the comment docs.

@fengmk2
Copy link
Member

fengmk2 commented Jul 3, 2017

加个循环100万次的 app.locals = obj (每个 obj 1MB 大小)测试用例,确保不修改就好导致内存泄漏。。。

果然是不加测试用例提交 pr 的习惯改不掉。

}
this[LOCALS_LIST].push(val);

assign(this[LOCALS], [ val ]);
Copy link
Member

Choose a reason for hiding this comment

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

直接 val 就可以了,没必要数组

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不行的。如果确实就想放一个数组呢。

这个地方的设计说实话还是有点问题的,后加的会将前面的覆盖。但如果想撤销前面的,需要挨个 设置 {key: null}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

或者应该加严格的判断,app.locals = 必须是一个 Object 并不能是 Array。

Copy link
Member

Choose a reason for hiding this comment

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

@@ -73,21 +72,15 @@ class Application extends EggApplication {
* @see Context#locals
*/
get locals() {
if (!this[LOCALS]) {
Copy link
Member

Choose a reason for hiding this comment

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

这个逻辑我改一下,保持原来的不变化。

@fengmk2
Copy link
Member

fengmk2 commented Jul 4, 2017

@JacksonTian 你不要改了,我修正了一个逻辑。等 ci 过了就合并。

@@ -76,18 +75,15 @@ class Application extends EggApplication {
if (!this[LOCALS]) {
Copy link
Member

Choose a reason for hiding this comment

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

这个逻辑不能变化的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个是为什么呢

Copy link
Member

Choose a reason for hiding this comment

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

看测试用例

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See.

@fengmk2 fengmk2 merged commit b80bb14 into master Jul 4, 2017
@fengmk2 fengmk2 deleted the locals branch July 4, 2017 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants