I've set up a page displaying a table of IP addresses connecting to a media stream. I've linked them to a database that includes location information and have managed to serve duplicate IP requests from cache to lighten the load. However, the page crashes with an Error: Insufficient Resources
message when too many requests are made simultaneously. I attempted batching using this library, but received a deprecation warning about
Synchronous XMLHttpRequest on main thread
, and it didn't seem to alleviate the issue either. How can I restrict the number of searches performed at once? I don't want to limit it to one at a time as it would be too slow otherwise. Here is the relevant code:
angular.forEach($scope.results, function(conn, key){
$http.get("addrinfo.cgi?action=get&addr="+conn.ip, { cache: true}) //$scope.results is a list of IP addresses
.then(function(ipLocation) {
console.log(ipLocation);
var locationResults = ipLocation.data;
conn.country = locationResults.country;
//... more assignments
});
});
Edit: I'm encountering difficulties implementing Paul's solution. I keep receiving a RequestManager is undefined
error. The structure of the code looks like this.
angular.module('ip-module', [
'app.controller',
'app.filter',
'app.factory'
]);
app.controller('ip-analysis', function($scope, $http, $q) { ... })
.filter('customNumFilter', function() { ... })
.factory('RequestManager', ['$http', '$scope', function() { ...
}]);