aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorAlexander Kabui2022-03-07 11:05:24 +0300
committerGitHub2022-03-07 11:05:24 +0300
commitf733cf955ed5137c4a1a67860b26bbaf23650c83 (patch)
treed55ca53915a58b6ca8d6aba747edd9ccdd7515fd /wqflask
parentc71218d9221789f850f5d93329f2d466527d3c52 (diff)
downloadgenenetwork2-f733cf955ed5137c4a1a67860b26bbaf23650c83.tar.gz
Fix/caching (#679)
* unlink file for JSONDecodeError * fix for avoiding caching empty dicts * fix for checking null dicts
Diffstat (limited to 'wqflask')
-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)