From a35db4b9616635ac041a24d4af969a3fed67f354 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 24 Feb 2010 14:47:10 -0500 Subject: [PATCH] Fixed the performance of the distance CSV generation. --- www/maps/maps/controllers/directions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/www/maps/maps/controllers/directions.py b/www/maps/maps/controllers/directions.py index dab8f66..0cd278f 100644 --- a/www/maps/maps/controllers/directions.py +++ b/www/maps/maps/controllers/directions.py @@ -88,31 +88,31 @@ class DirectionsController(BaseController): def directions_result_to_csv(self, result): - row = '' + rows = [] for trip in result['trips']: for route in trip['routes']: route_start = self.get_route_address(route, True) route_end = self.get_route_address(route, False) - row += '"' + route_start + '"' + row = '"' + route_start + '"' row += ', ' row += '"' + route_end + '"' row += ', ' row += str(float(route['distance']['value']) / 1000) - row += "\n" + rows.append(row) - return row + return rows def distances(self): directions_array = json.loads(request.POST['data']) - csv = '' + csv_rows = [] for result in directions_array: - csv += self.directions_result_to_csv(result) + csv_rows += self.directions_result_to_csv(result) response.content_type = 'text/csv' response.headers['Content-disposition'] = 'attachment; filename=distances.csv' - return csv + return "\n".join(csv_rows) -- 2.44.2