utils: use schema mtime as cache key (#39153)

This commit is contained in:
Benjamin Dauvergne 2020-01-21 22:57:59 +01:00
parent 0d8b5bd8ef
commit 65f023086a
1 changed files with 9 additions and 4 deletions

View File

@ -41,17 +41,22 @@ def get_warehouses_paths():
@lru_cache()
def get_warehouse_by_path_and_mtime(path, mtime):
warehouse = json.load(open(path))
warehouse['path'] = path
return Warehouse.from_json(warehouse)
def get_warehouses_by_paths(paths):
warehouses = []
for path in paths:
d = json.load(open(path))
d['path'] = path
warehouses.append(Warehouse.from_json(d))
mtime = os.path.getmtime(path)
warehouses.append(get_warehouse_by_path_and_mtime(path, mtime))
return warehouses
def get_warehouses():
paths = frozenset(get_warehouses_paths())
paths = get_warehouses_paths()
return get_warehouses_by_paths(paths)