From 89d45cc0927bf4e86112f026f75e709da0bd660e Mon Sep 17 00:00:00 2001 From: Spyros Date: Tue, 24 Oct 2023 19:26:24 +0100 Subject: [PATCH] minor changes --- application/database/db.py | 15 ++++++--------- application/web/web_main.py | 8 ++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/application/database/db.py b/application/database/db.py index 03681a7db..0e9086b3a 100644 --- a/application/database/db.py +++ b/application/database/db.py @@ -1636,7 +1636,7 @@ def add_embedding( return existing - def get_gap_analysis_result(self, cache_key): + def get_gap_analysis_result(self, cache_key)->str: res = ( self.session.query(GapAnalysisResults) .filter(GapAnalysisResults.cache_key == cache_key) @@ -1645,17 +1645,14 @@ def get_gap_analysis_result(self, cache_key): if res: return res.ga_object - def add_gap_analysis_result(self, cache_key: str, ga_object: dict): + def add_gap_analysis_result(self, cache_key: str, ga_object: str): existing = self.get_gap_analysis_result(cache_key) if not existing: res = GapAnalysisResults( - cache_key=cache_key, ga_object=flask_json.dumps(ga_object) + cache_key=cache_key, ga_object=ga_object ) self.session.add(res) self.session.commit() - else: - return existing - def dbNodeFromNode(doc: cre_defs.Node) -> Optional[Node]: if doc.doctype == cre_defs.Credoctypes.Standard: @@ -1837,14 +1834,14 @@ def gap_analysis( # conn.set(cache_key, flask_json.dumps({"result": grouped_paths})) cre_db.add_gap_analysis_result( - cache_key=cache_key, ga_object={"result": grouped_paths} + cache_key=cache_key, ga_object=flask_json.dumps({"result": grouped_paths}) ) for key in extra_paths_dict: cre_db.add_gap_analysis_result( cache_key=make_cache_key(node_names, key), - ga_object={"result": extra_paths_dict[key]}, - ) + ga_object=flask_json.dumps({"result": extra_paths_dict[key]}), + ) # conn.set( # cache_key + "->" + key, # flask_json.dumps({"result": extra_paths_dict[key]}), diff --git a/application/web/web_main.py b/application/web/web_main.py index 41ba1e64b..73964e815 100644 --- a/application/web/web_main.py +++ b/application/web/web_main.py @@ -228,9 +228,9 @@ def gap_analysis() -> Any: standards_hash = make_array_hash(standards) result = database.get_gap_analysis_result(standards_hash) if result: - gap_analysis_dict = json.loads(result) + gap_analysis_dict = flask_json.loads(result) if gap_analysis_dict.get("result"): - return jsonify({"result": gap_analysis_dict.get("result")}) + return jsonify(gap_analysis_dict) gap_analysis_results = conn.get(standards_hash) if gap_analysis_results: @@ -327,9 +327,9 @@ def fetch_job() -> Any: ga = database.get_gap_analysis_result(standards_hash) if ga: logger.info("and results in cache") - ga = json.loads(ga) + ga = flask_json.loads(ga) if ga.get("result"): - return jsonify({"result": ga.get("result")}) + return jsonify(ga) else: logger.error( "Finished job does not have a result object, this is a bug!"