Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Oct 24, 2023
1 parent 04ae6e6 commit 89d45cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 6 additions & 9 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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]}),
Expand Down
8 changes: 4 additions & 4 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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!"
Expand Down

0 comments on commit 89d45cc

Please sign in to comment.