aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/correlation/pre_computes.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/wqflask/wqflask/correlation/pre_computes.py b/wqflask/wqflask/correlation/pre_computes.py
index 975a53b8..cb2f4470 100644
--- a/wqflask/wqflask/correlation/pre_computes.py
+++ b/wqflask/wqflask/correlation/pre_computes.py
@@ -6,29 +6,40 @@ from pathlib import Path
from base.data_set import query_table_timestamp
from base.webqtlConfig import TMPDIR
+from json.decoder import JSONDecodeError
+
def fetch_all_cached_metadata(dataset_name):
"""in a gvein dataset fetch all the traits metadata"""
file_name = generate_filename(dataset_name, suffix="metadata")
- file_path = os.path.join(TMPDIR, file_name)
+ file_path = Path(TMPDIR, file_name)
try:
with open(file_path, "r+") as file_handler:
dataset_metadata = json.load(file_handler)
+
return (file_path, dataset_metadata)
except FileNotFoundError:
- Path(file_path).touch(exist_ok=True)
- return (file_path, {})
+ pass
+
+ except JSONDecodeError:
+ file_path.unlink()
+
+ file_path.touch(exist_ok=True)
+
+ return (file_path, {})
def cache_new_traits_metadata(dataset_metadata: dict, new_traits_metadata, file_path: str):
"""function to cache the new traits metadata"""
- if bool(new_traits_metadata):
- dataset_metadata.update(new_traits_metadata)
-
+ if (dataset_metadata == {} and new_traits_metadata == {}):
+ return
+
+ dataset_metadata.update(new_traits_metadata)
+
with open(file_path, "w+") as file_handler:
json.dump(dataset_metadata, file_handler)