-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BUGFIX beta] [PERF] Cache FactoryManagers #15009
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ export default function Container(registry, options) { | |
this.owner = options && options.owner ? options.owner : null; | ||
this.cache = dictionary(options && options.cache ? options.cache : null); | ||
this.factoryCache = dictionary(options && options.factoryCache ? options.factoryCache : null); | ||
this.factoryManagerCache = dictionary(options && options.factoryCache ? options.factoryCache : null); | ||
this.validationCache = dictionary(options && options.validationCache ? options.validationCache : null); | ||
this._fakeContainerToInject = buildFakeContainerWithDeprecations(this); | ||
this[CONTAINER_OVERRIDE] = undefined; | ||
|
@@ -281,6 +282,7 @@ if (isFeatureEnabled('ember-factory-for')) { | |
*/ | ||
Container.prototype.factoryFor = function _factoryFor(fullName, options = {}) { | ||
let normalizedName = this.registry.normalize(fullName); | ||
|
||
assert('fullName must be a proper full name', this.registry.validateFullName(normalizedName)); | ||
|
||
if (options.source) { | ||
|
@@ -289,16 +291,23 @@ if (isFeatureEnabled('ember-factory-for')) { | |
if (!normalizedName) { return; } | ||
} | ||
|
||
let cached = this.factoryManagerCache[normalizedName]; | ||
|
||
if (cached) { return cached; } | ||
|
||
let factory = this.registry.resolve(normalizedName); | ||
|
||
if (factory === undefined) { return; } | ||
if (factory === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should misses not cache? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought so, but there where test failures and I'm tired :P Maybe i can convince @chadhietala to investigate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return; | ||
} | ||
|
||
let manager = new FactoryManager(this, factory, fullName, normalizedName); | ||
|
||
runInDebug(() => { | ||
manager = wrapManagerInDeprecationProxy(manager); | ||
}); | ||
|
||
this.factoryManagerCache[normalizedName] = manager; | ||
return manager; | ||
}; | ||
} | ||
|
@@ -669,13 +678,14 @@ class FactoryManager { | |
this.class = factory; | ||
this.fullName = fullName; | ||
this.normalizedName = normalizedName; | ||
this.madeToString = undefined; | ||
} | ||
|
||
create(options = {}) { | ||
let injections = injectionsFor(this.container, this.normalizedName); | ||
let props = assign({}, injections, options); | ||
|
||
props[NAME_KEY] = this.container.registry.makeToString(this.class, this.fullName); | ||
props[NAME_KEY] = this.madeToString || (this.madeToString = this.container.registry.makeToString(this.class, this.fullName)); | ||
|
||
runInDebug(() => { | ||
let lazyInjections; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not share the same cache as
this.factoryCache
. I suspect this should be:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit fixing this