From 3e03d40de2f72338e177c70505060eaec0632cb6 Mon Sep 17 00:00:00 2001 From: Joe Flack Date: Wed, 27 Nov 2024 00:19:58 -0500 Subject: [PATCH] Fix expression items - Addresses issue where expressions could be out of sync between the enclave and DB, i.e. some may have been added or deleted since when they became drafts and when they were imported into the DB, and the DB did not get those udpates. --- backend/db/resolve_fetch_failures_0_members.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/db/resolve_fetch_failures_0_members.py b/backend/db/resolve_fetch_failures_0_members.py index fdae7c5f2..664567e24 100644 --- a/backend/db/resolve_fetch_failures_0_members.py +++ b/backend/db/resolve_fetch_failures_0_members.py @@ -42,7 +42,7 @@ def _report_success( fetch_status_set_success(success_rows, use_local_db) -def _ad_hoc_detect_and_delete_discarded_drafts(schema: str = SCHEMA, local: bool = False): +def _ad_hoc_detect_and_delete_discarded_drafts(schema=SCHEMA, local=False): """Check all csets currently marked draft in the DB, check if discarded, and handle.""" with get_db_connection(schema=schema, local=local) as con: rows: List[List[int]] = sql_query( @@ -54,6 +54,20 @@ def _ad_hoc_detect_and_delete_discarded_drafts(schema: str = SCHEMA, local: bool handle_discarded_drafts(con, csets_and_members, set(draft_ids), report_success=False, use_local_db=local) +def _ad_hoc_sync_draft_expression_items(since='2023-08-15', schema=SCHEMA, local=False): + """Syncronizes all expression items since specified date. + + Syncs just the presence of them in the DB, not their field values) between the enclave and TermHub + Default value 2023-08-15: 1 day before we implemented inclusion of drafts. This last ran on 2024/11/16, + synchronizing all csets that were were created since that date. + """ + with get_db_connection(schema=schema, local=local) as con: + rows: List[List[int]] = sql_query( + con, f"SELECT codeset_id FROM code_sets WHERE created_at > {since};", return_with_keys=False) + cset_ids: List[int] = [x[0] for x in rows] + resolve_fetch_failures_0_members(cset_ids, local, schema=schema, force=True) + + def handle_discarded_drafts( con: Connection, csets_and_members: Dict[str, List[Dict]], queried_cset_ids: Set[int], failure_lookup: Dict[int, Dict] = None, report_success=True, use_local_db=False