mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Deferred URL generation until after filter
- it turns out we it the false case of this if-statement quite a lot, and _generateUrl is heavy enough that we should try and do it less - by moving it into the if-statement, we cut 4% CPU time from boot on heavy sites
This commit is contained in:
parent
70eb96f33a
commit
90fbbe135f
2 changed files with 2 additions and 3 deletions
|
@ -170,11 +170,10 @@ class UrlGenerator {
|
|||
return false;
|
||||
}
|
||||
|
||||
const url = this._generateUrl(resource);
|
||||
|
||||
// CASE 1: route has no custom filter, it will own the resource for sure
|
||||
// CASE 2: find out if my filter matches the resource
|
||||
if ((!this.filter) || (this.nql.queryJSON(resource.data))) {
|
||||
const url = this._generateUrl(resource);
|
||||
this.urls.add({
|
||||
url: url,
|
||||
generatorId: this.uid,
|
||||
|
|
|
@ -263,7 +263,7 @@ describe('Unit: services/url/UrlGenerator', function () {
|
|||
|
||||
urlGenerator._try(resource);
|
||||
|
||||
urlGenerator._generateUrl.calledOnce.should.be.true();
|
||||
urlGenerator._generateUrl.calledOnce.should.be.false();
|
||||
urlGenerator._resourceListeners.called.should.be.false();
|
||||
urls.add.called.should.be.false();
|
||||
resource.reserve.called.should.be.false();
|
||||
|
|
Loading…
Add table
Reference in a new issue