Skip to content

Commit

Permalink
use exception instead of check to avoid db hit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeety4 committed Dec 13, 2024
1 parent f4bc32e commit 4864944
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion corehq/apps/userreports/sql/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def get_table(self):
@memoized
def get_existing_table_from_db(self):
"""Loads existing table directly from database if one exists"""
if self.table_exists:
try:
return sqlalchemy.Table(self.get_table().name, sqlalchemy.MetaData(), autoload_with=self.engine)
except sqlalchemy.exc.NoSuchTableError:
pass

@property
def table_exists(self):
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/userreports/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ def rebuild_indicators_in_place(indicator_config_id, initiated_by=None, source=N


def _get_rows_count_from_existing_table(adapter):
if not adapter.table_exists:
return None
table = adapter.get_existing_table_from_db()
if not table:
return None
return adapter.session_helper.Session.query(table).count()


Expand Down

0 comments on commit 4864944

Please sign in to comment.