From 699737bc40aebce3e53678a2726378f8e649c1a1 Mon Sep 17 00:00:00 2001 From: Helldragon67 Date: Tue, 28 Jan 2025 16:24:51 +0100 Subject: [PATCH] more docs --- backend/src/main.py | 2 +- backend/src/overpass/caching_strategy.py | 25 ++++++++++++++++++++++++ backend/src/overpass/overpass.py | 21 -------------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/backend/src/main.py b/backend/src/main.py index 104ff08..54c8b44 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -14,7 +14,7 @@ from .utils.landmarks_manager import LandmarkManager from .utils.toilets_manager import ToiletsManager from .optimization.optimizer import Optimizer from .optimization.refiner import Refiner -from .overpass.overpass import fill_cache +from .overpass.caching_strategy import fill_cache from .cache import client as cache_client diff --git a/backend/src/overpass/caching_strategy.py b/backend/src/overpass/caching_strategy.py index d7bc5aa..d2c5add 100644 --- a/backend/src/overpass/caching_strategy.py +++ b/backend/src/overpass/caching_strategy.py @@ -3,6 +3,7 @@ import json import hashlib from ..constants import OSM_CACHE_DIR, OSM_TYPES +from .overpass import Overpass def get_cache_key(query: str) -> str: @@ -133,3 +134,27 @@ class CachingStrategy: selector: str, conditions: list=None, out='center'): """Create a hollow cache entry.""" cls.__strategy.set_hollow(key, cell, osm_types, selector, conditions, out) + + +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 {f} as .json file') diff --git a/backend/src/overpass/overpass.py b/backend/src/overpass/overpass.py index cb692ca..17a1031 100644 --- a/backend/src/overpass/overpass.py +++ b/backend/src/overpass/overpass.py @@ -321,24 +321,3 @@ 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(): - - overpass = Overpass() - - with os.scandir(OSM_CACHE_DIR) as it: - for entry in it: - if entry.is_file() and entry.name.startswith('hollow_'): - - # Read the whole file content as a string - with open(entry.path, 'r') as f: - try : - # load data and fill the cache with the query and key - json_data = json.load(f) - overpass.fill_cache(json_data) - except Exception as exc : - overpass.logger.error(f'An error occured while parsing file {f} as .json file') - - # Now delete the file as the cache is filled - os.remove(entry.path)