better logs
Some checks failed
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
Some checks failed
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
This commit is contained in:
@@ -52,10 +52,11 @@ class Overpass :
|
||||
|
||||
# If there is no missing data, return the cached responses
|
||||
if not hollow_cache_keys :
|
||||
self.logger.info('Cache hit.')
|
||||
self.logger.info(f'Cache hit for {len(cached_responses)} quadrants.')
|
||||
return self._combine_cached_data(cached_responses)
|
||||
|
||||
# TODO If there is SOME missing data : hybrid stuff with partial cache
|
||||
self.logger.info(f'Cache miss for {len(hollow_cache_keys)} quadrants.')
|
||||
|
||||
# Missing data: Make a query to Overpass API
|
||||
query_str = Overpass.build_query(bbox, osm_types, selector, conditions, out)
|
||||
@@ -80,9 +81,7 @@ class Overpass :
|
||||
response_data = response.read().decode('utf-8') # Convert the HTTPResponse to a string
|
||||
data = json.loads(response_data) # Load the JSON from the string
|
||||
elements = data.get('elements', [])
|
||||
|
||||
self.logger.info(f'Cache miss. Fetching data through Overpass.')
|
||||
self.logger.debug(f'Query = {query_str}')
|
||||
# self.logger.debug(f'Query = {query_str}')
|
||||
return elements
|
||||
|
||||
except urllib.error.URLError as e:
|
||||
@@ -321,3 +320,27 @@ def get_base_info(elem: dict, osm_type: OSM_TYPES, with_name=False) :
|
||||
return osm_id, coords, name
|
||||
else :
|
||||
return osm_id, coords
|
||||
|
||||
|
||||
def fill_cache():
|
||||
"""
|
||||
Scans the specified cache directory for files starting with 'hollow_' and attempts to load
|
||||
their contents as JSON to fill the cache of the Overpass system.
|
||||
"""
|
||||
overpass = Overpass()
|
||||
|
||||
with os.scandir(OSM_CACHE_DIR) as it:
|
||||
for entry in it:
|
||||
if entry.is_file() and entry.name.startswith('hollow_'):
|
||||
|
||||
try :
|
||||
# Read the whole file content as a string
|
||||
with open(entry.path, 'r') as f:
|
||||
# load data and fill the cache with the query and key
|
||||
json_data = json.load(f)
|
||||
overpass.fill_cache(json_data)
|
||||
# Now delete the file as the cache is filled
|
||||
os.remove(entry.path)
|
||||
|
||||
except Exception as exc :
|
||||
overpass.logger.error(f'An error occured while parsing file {entry.path} as .json file')
|
||||
|
Reference in New Issue
Block a user