perf($http): move xsrf cookie check to after cache check in $http

$http was previously checking cookies to find an xsrf-token prior to checking
the cache. This caused a performance penalty of about 2ms, which can be very
significant when loading hundreds of template instances on a page.

Fixes #7717
This commit is contained in:
Michal Kawalec
2014-06-09 15:54:09 +02:00
committed by Jeff Cross
parent 9b51067516
commit 8b86d363aa
2 changed files with 29 additions and 9 deletions

View File

@@ -860,6 +860,25 @@ describe('$http', function() {
$httpBackend.flush();
}));
it('should check the cache before checking the XSRF cookie', inject(function($browser, $cacheFactory) {
var testCache = $cacheFactory('testCache'),
executionOrder = [];
spyOn($browser, 'cookies').andCallFake(function() {
executionOrder.push('cookies');
return {'XSRF-TOKEN':'foo'};
});
spyOn(testCache, 'get').andCallFake(function() {
executionOrder.push('cache');
});
$httpBackend.expect('GET', '/url', undefined).respond('');
$http({url: '/url', method: 'GET', cache: testCache});
$httpBackend.flush();
expect(executionOrder).toEqual(['cache', 'cookies']);
}));
});