diff --git a/app/contacts_cache.py b/app/contacts_cache.py index 0e7383d..5c5faf8 100644 --- a/app/contacts_cache.py +++ b/app/contacts_cache.py @@ -11,6 +11,7 @@ parse_advert_payload(). import logging import math import struct +from flask import current_app logger = logging.getLogger(__name__) @@ -18,9 +19,8 @@ _TYPE_LABELS = {0: 'COM', 1: 'COM', 2: 'REP', 3: 'ROOM', 4: 'SENS'} def _get_db(): - """Get database instance (deferred import to avoid circular imports).""" - from app.main import db - return db + """Get database instance from Flask app context.""" + return getattr(current_app, 'db', None) def get_all_contacts() -> list: diff --git a/app/read_status.py b/app/read_status.py index a4a2f2a..af81ed3 100644 --- a/app/read_status.py +++ b/app/read_status.py @@ -7,14 +7,14 @@ All data is stored in the read_status table of the SQLite database. """ import logging +from flask import current_app logger = logging.getLogger(__name__) def _get_db(): - """Get database instance (deferred import to avoid circular imports).""" - from app.main import db - return db + """Get database instance from Flask app context.""" + return getattr(current_app, 'db', None) def load_read_status():