Commit dca2b847824d4d5fc3b8cf3553dace66b63a2d1c

Authored by Antoine Goutenoir
1 parent 59125398
Exists in master

Cap the amount of locations allowed.

Showing 1 changed file with 17 additions and 3 deletions   Show diff stats
flaskr/controllers/main_controller.py
... ... @@ -228,6 +228,8 @@ def invalidate():
228 228 @main.route("/compute")
229 229 def compute(): # process the queue of estimation requests
230 230  
  231 + maximum_addresses_to_compute = 30000
  232 +
231 233 def _respond(_msg):
232 234 return "<pre>%s</pre>" % _msg
233 235  
... ... @@ -276,9 +278,15 @@ def compute(): # process the queue of estimation requests
276 278 # GEOCODE ORIGINS #########################################################
277 279  
278 280 origins_addresses = estimation.origin_addresses.strip().split("\n")
  281 + origins_addresses_count = len(origins_addresses)
279 282 origins = []
280 283  
281   - for i in range(len(origins_addresses)):
  284 + if origins_addresses_count > maximum_addresses_to_compute:
  285 + errmsg = "Too many origins. (%d > %d) Please contact us for support of that many origins." % (origins_addresses_count, maximum_addresses_to_compute)
  286 + _handle_failure(estimation, errmsg)
  287 + return _respond(errmsg)
  288 +
  289 + for i in range(origins_addresses_count):
282 290  
283 291 origin_address = origins_addresses[i].strip()
284 292 if origin_address in failed_addresses:
... ... @@ -312,9 +320,15 @@ def compute(): # process the queue of estimation requests
312 320 # GEOCODE DESTINATIONS ####################################################
313 321  
314 322 destinations_addresses = estimation.destination_addresses.strip().split("\n")
  323 + destinations_addresses_count = len(destinations_addresses)
315 324 destinations = []
316 325  
317   - for i in range(len(destinations_addresses)):
  326 + if destinations_addresses_count > maximum_addresses_to_compute:
  327 + errmsg = "Too many destinations. (%d > %d) Please contact us for support of that many destinations." % (destinations_addresses_count, maximum_addresses_to_compute)
  328 + _handle_failure(estimation, errmsg)
  329 + return _respond(errmsg)
  330 +
  331 + for i in range(destinations_addresses_count):
318 332  
319 333 destination_address = destinations_addresses[i].strip()
320 334 if destination_address in failed_addresses:
... ... @@ -555,7 +569,7 @@ def compute(): # process the queue of estimation requests
555 569 return _respond(response)
556 570  
557 571 except Exception as e:
558   - errmsg = "Computation failed : %s" % e
  572 + errmsg = "Computation failed : %s" % (e,)
559 573 if estimation:
560 574 _handle_failure(estimation, errmsg)
561 575 return _respond(errmsg)
... ...