From bfbcd60c383f231571a6b55dc9644da88b672c82 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Tue, 6 Sep 2022 15:45:10 +0300 Subject: Remove intermediate variables that are only used once * wqflask/base/data_set.py (DatasetGroup.__init__): Remove "query" variable. (DataSet.chunk_dataset): Fix indentation. * wqflask/wqflask/search_results.py (get_GO_symbols): Remove "this_term" variable. * wqflask/wqflask/views.py (search_page): Remove "the_search" variable. --- wqflask/base/data_set.py | 24 ++++++++++++++---------- wqflask/wqflask/search_results.py | 6 +----- wqflask/wqflask/views.py | 4 +--- 3 files changed, 16 insertions(+), 18 deletions(-) (limited to 'wqflask') diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 41c94078..b877f176 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -316,16 +316,20 @@ class DatasetGroup: def __init__(self, dataset, name=None): """This sets self.group and self.group_id""" - query = """SELECT InbredSet.Name, InbredSet.Id, InbredSet.GeneticType, - InbredSet.InbredSetCode FROM InbredSet where Name=%s - """ - if not name: - query, name = dataset.query_for_group, dataset.name with database_connection() as conn, conn.cursor() as cursor: - cursor.execute(query, (name,)) - results = cursor.fetchone() - if results: - self.name, self.id, self.genetic_type, self.code = results + if not name: + cursor.execute(dataset.query_for_group, + (dataset.name,)) + else: + cursor.execute( + "SELECT InbredSet.Name, " + "InbredSet.Id, " + "InbredSet.GeneticType, " + "InbredSet.InbredSetCode " + "FROM InbredSet WHERE Name = %s", + (dataset.name,)) + (self.name, self.id, + self.genetic_type, self.code) = cursor.fetchone() if self.name == 'BXD300': self.name = "BXD" @@ -672,7 +676,7 @@ class DataSet: "WHERE ProbeSetFreeze.Name = %s AND " "ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id " "AND ProbeSetXRef.ProbeSetId = ProbeSet.Id", - (self.name,)) + (self.name,)) # should cache this traits_name_dict = dict(cursor.fetchall()) diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index 061fe5b3..bd6d1f79 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -388,11 +388,7 @@ def get_GO_symbols(a_search): new_terms = [] for gene in gene_list: - this_term = dict(key=None, - separator=None, - search_term=[gene]) - - new_terms.append(this_term) + new_terms.append(dict(key=None, separator=None, search_term=[gene])) return new_terms diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 02c534a2..174913e4 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -179,10 +179,8 @@ def search_page(): result = Redis.get(key) if result: result = pickle.loads(result) - the_search = SearchResultPage(request.args) - result = the_search.__dict__ + result = SearchResultPage(request.args).__dict__ valid_search = result['search_term_exists'] - if USE_REDIS and valid_search: Redis.set(key, pickle.dumps(result, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60 * 60) -- cgit v1.2.3