From b187a106e4018b36166bcb736a966a2fbdc29e91 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Mon, 19 Jun 2017 12:01:10 +0200 Subject: [PATCH] Avoid loading multiple times the same data There was a bug in `data.py` which made it load the same data as many times as the number of postal codes in constraints. This is now fixed. --- flatisfy/data.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flatisfy/data.py b/flatisfy/data.py index 698bd63..20de512 100644 --- a/flatisfy/data.py +++ b/flatisfy/data.py @@ -83,8 +83,13 @@ def load_data(model, constraint, config): get_session = database.init_db(config["database"], config["search_index"]) results = [] with get_session() as session: + areas = [] + # Get areas to fetch from, using postal codes for postal_code in constraint["postal_codes"]: - area = data_files.french_postal_codes_to_iso_3166(postal_code) + areas.append(data_files.french_postal_codes_to_iso_3166(postal_code)) + # Load data for each area + areas = list(set(areas)) + for area in areas: results.extend( session.query(model) .filter(model.area == area).all()