aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base
diff options
context:
space:
mode:
authorAlexander Kabui2021-11-17 20:20:07 +0300
committerAlexander Kabui2021-11-17 20:20:07 +0300
commit6786712e95cbb885b6b19b3ecd34e6c8ee893172 (patch)
treeea13da52164170e5fec9108d5dc10eb053116ae4 /wqflask/base
parenta35ae60965d7cada41acad661afd88a8fc58e78e (diff)
downloadgenenetwork2-6786712e95cbb885b6b19b3ecd34e6c8ee893172.tar.gz
refactor sql query & date formatting
Diffstat (limited to 'wqflask/base')
-rw-r--r--wqflask/base/data_set.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index 52d1d254..2687738d 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -1258,31 +1258,27 @@ def geno_mrna_confidentiality(ob):
return True
-
def parse_db_url():
parsed_db = urlparse(SQL_URI)
return (parsed_db.hostname, parsed_db.username,
parsed_db.password, parsed_db.path[1:])
+
def query_table_timestamp(dataset_type: str):
"""function to query the update timestamp of a given dataset_type"""
# computation data and actions
fetch_db_name = parse_db_url()
-
query_update_time = f"""
SELECT UPDATE_TIME FROM information_schema.tables
- WHERE TABLE_SCHEMA = {fetch_db_name[-1]}
+ WHERE TABLE_SCHEMA = '{fetch_db_name[-1]}'
AND TABLE_NAME = '{dataset_type}Data'
"""
- # store the timestamp in redis=
date_time_obj = g.db.execute(query_update_time).fetchone()[0]
-
- f = "%Y-%m-%d %H:%M:%S"
- return date_time_obj.strftime(f)
+ return date_time_obj.strftime("%Y-%m-%d %H:%M:%S")
def generate_hash_file(dataset_name: str, dataset_type: str, dataset_timestamp: str):
@@ -1301,6 +1297,7 @@ def cache_dataset_results(dataset_name: str, dataset_type: str, query_results: L
table_timestamp = query_table_timestamp(dataset_type)
+
file_name = generate_hash_file(dataset_name, dataset_type, table_timestamp)
file_path = os.path.join(TMPDIR, f"{file_name}.json")