From c83dc9f45d6df6faa7d95916a998ded9be3167fa Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 22 Oct 2021 15:26:20 +0300 Subject: fetch cached results --- wqflask/base/data_set.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'wqflask') diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 8188d90c..51244303 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -1243,7 +1243,7 @@ def geno_mrna_confidentiality(ob): return True -def check_if_dataset_modified(dataset_name, cached_timestamp): +def check_if_dataset_modified(dataset_name: str, cached_timestamp): """function to check if the dataset has been modified""" last_modified = "query results" return (cached_timestamp == last_modified_timestamp) @@ -1264,4 +1264,18 @@ def cache_dataset_results(dataset_name: str, query_results: List): query_results = [list(results) for result in query_results] with open(file_path, "w") as file_handler: - json.dump(query_results, file_handler) \ No newline at end of file + json.dump(query_results, file_handler) + +def fetch_cached_results(dataset_name: str): + """function to fetch the cached results""" + file_path = os.path.join(TMPDIR, f"{dataset_name}.json") + + try: + with open(file_path) as file_handler: + data = json.load(file_handler) + # check if table has been modified + if check_if_dataset_modified(dataset_name["timestamp"]): + return data[dataset_name] + except FileNotFoundError: + # take actions continue to fetch dataset results and fetch results + pass \ No newline at end of file -- cgit v1.2.3