Browse Source

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.
merge-requests/10/head
Lucas Verney 5 years ago
parent
commit
b187a106e4
  1. 7
      flatisfy/data.py

7
flatisfy/data.py

@ -83,8 +83,13 @@ def load_data(model, constraint, config): @@ -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()

Loading…
Cancel
Save