Skip to content

Commit

Permalink
fix load_stations
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikelimper committed Sep 22, 2023
1 parent 87c2c17 commit 1f55a38
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions wis2box-management/wis2box/metadata/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,21 @@ def load_stations(wsi='') -> dict:

try:
es = Elasticsearch(API_BACKEND_URL)
nbatch = 50
nbatch = 500
res = es.search(index="stations", query={"match_all": {}}, size=nbatch) # noqa
if len(res['hits']['hits']) == 0:
LOGGER.debug('No stations found')
return stations
for hit in res['hits']['hits']:
if wsi != '' and hit['_source']['id'] != wsi:
continue
stations[hit['_source']['id']] = hit['_source']
if wsi != '' and wsi in stations:
return {wsi: stations[wsi]}
if wsi != '':
stations = {}
while len(res['hits']['hits']) > 0:
res = es.search(index="stations", query={"match_all": {}}, size=nbatch, from_=len(stations)) # noqa
for hit in res['hits']['hits']:
if wsi != '' and hit['_source']['id'] != wsi:
continue
stations[hit['_source']['id']] = hit['_source']
if wsi != '' and wsi in stations:
return {wsi: stations[wsi]}
if wsi != '':
stations = {}
except Exception as err:
LOGGER.error(f'Failed to load stations from backend: {err}')

Expand Down

0 comments on commit 1f55a38

Please sign in to comment.