From beff6962223c1885697c5755878a0b694d210965 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 18 Jul 2023 13:39:18 +0300 Subject: Replace ORM calls with direct queries Avoid the use of the ORM code for fetching data from the database, and instead use direct queries that indicate easily what is being fetched from the database. --- wqflask/wqflask/metadata_edits.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index a3b7f307..9decbc16 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -52,6 +52,7 @@ from gn3.db.phenotypes import Phenotype from gn3.db.phenotypes import Probeset from gn3.db.phenotypes import Publication from gn3.db.phenotypes import PublishXRef +from gn3.db.phenotypes import fetch_trait, fetch_metadata, fetch_publication from gn3.db.phenotypes import probeset_mapping from gn3.db.sample_data import delete_sample_data from gn3.db.sample_data import get_trait_sample_data, get_trait_csv_sample_data @@ -92,23 +93,11 @@ def _get_diffs(diff_dir: str, redis_conn: redis.Redis): def edit_phenotype(conn, name, dataset_id): - publish_xref = fetchone( - conn=conn, - table="PublishXRef", - where=PublishXRef(id_=name, inbred_set_id=dataset_id), - ) + publish_xref = fetch_trait(conn, dataset_id=dataset_id, trait_name=name) return { "publish_xref": publish_xref, - "phenotype": fetchone( - conn=conn, - table="Phenotype", - where=Phenotype(id_=publish_xref.phenotype_id), - ), - "publication": fetchone( - conn=conn, - table="Publication", - where=Publication(id_=publish_xref.publication_id), - ), + "phenotype": fetch_metadata(conn, publish_xref["phenotype_id"]), + "publication": fetch_publication(conn, publish_xref["publication_id"]) } @@ -135,7 +124,7 @@ def display_phenotype_metadata(dataset_id: str, name: str): group_name = retrieve_phenotype_group_name(conn, dataset_id) sample_list = retrieve_sample_list(group_name) - sample_data = get_trait_sample_data(conn, name, _d.get("publish_xref").phenotype_id) + sample_data = get_trait_sample_data(conn, name, _d["publish_xref"]["phenotype_id"]) return render_template( "edit_phenotype.html", -- cgit v1.2.3