Add data retention configuration and cleanup functionality

- Introduced a new `[Data_Retention]` section in `config.ini.example` to manage retention periods for various database tables, including packet stream, daily stats, and observed paths.
- Updated `mkdocs.yml` and `configuration.md` to include documentation for the new data retention settings.
- Implemented data retention cleanup methods in `mesh_graph.py`, `repeater_manager.py`, and `scheduler.py` to enforce retention policies automatically.
- Enhanced the web viewer's data cleanup logic to utilize the new retention settings, ensuring efficient database management.
This commit is contained in:
agessaman committed 2026-02-24 22:01:49 -08:00
1 parent 513d1ec65b
commit fcfde7ea33
9 files changed
+233 -8

No files matched your search

+22
View File
@@ -717,6 +717,28 @@ class MeshGraph:
self.logger.debug(f"Pruned {len(expired_keys)} expired graph edges (older than {self.edge_expiration_days} days)")
return len(expired_keys)
def delete_expired_edges_from_db(self, days: int) -> int:
"""Delete mesh_connections rows older than the given days.
Keeps the on-disk table aligned with in-memory pruning and prevents unbounded growth.
Called from the scheduler (e.g. daily). Use Data_Retention mesh_connections_retention_days
or Path_Command graph_edge_expiration_days.
Returns:
int: Number of rows deleted.
"""
if days <= 0:
return 0
try:
deleted = self.db_manager.execute_update(
"DELETE FROM mesh_connections WHERE last_seen < datetime('now', ?)",
(f'-{days} days',)
)
if deleted > 0:
self.logger.info(f"Cleaned up {deleted} old mesh_connections entries (older than {days} days)")
return deleted
except Exception as e:
self.logger.error(f"Error cleaning up mesh_connections: {e}")
return 0
def _start_batch_writer(self):
"""Start background task for batched writes."""
def batch_writer_loop():