more docs
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 / Build and push image (pull_request) Successful in 1m39s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 24s
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 / Build and push image (pull_request) Successful in 1m39s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 24s
This commit is contained in:
parent
1240f86d6e
commit
699737bc40
@ -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
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user