updated view and database

This commit is contained in:
ske087
2026-06-24 15:21:40 +03:00
parent cb12a8f1cf
commit a48b3afb83
14 changed files with 372 additions and 205 deletions
+12 -2
View File
@@ -13,8 +13,15 @@ class DeviceService:
"""Service for managing devices and device-related operations"""
def __init__(self):
self.db = get_db()
self._db = None
self.logger = logging.getLogger(__name__)
@property
def db(self):
"""Lazily resolve the database handle (see LogCompressionService.db)."""
if self._db is None:
self._db = get_db()
return self._db
# Basic CRUD Operations
@@ -213,7 +220,10 @@ class DeviceService:
'recent_logs_24h': recent_logs,
'total_files': total_files,
'last_log': last_log,
'uptime_days': (datetime.utcnow() - device.last_seen).days if device.last_seen else 0
# Days since the device was last seen (0 = seen today / currently active).
# Previously mislabeled as "uptime_days" which implied the opposite.
'days_since_last_seen': (datetime.utcnow() - device.last_seen).days if device.last_seen else None,
'is_online': device.is_online,
}
except Exception as e: