Misc cruft -- filtering, pagination tests, etc.

This commit is contained in:
Jack Kingsman
2026-02-24 21:03:24 -08:00
parent 684724913f
commit 1c2fb148bc
6 changed files with 210 additions and 11 deletions
+7
View File
@@ -38,6 +38,13 @@ async def lifespan(app: FastAPI):
await db.connect()
logger.info("Database connected")
# Ensure default channels exist in the database even before the radio
# connects. Without this, a fresh or disconnected instance would return
# zero channels from GET /channels until the first successful radio sync.
from app.radio_sync import ensure_default_channels
await ensure_default_channels()
try:
await radio_manager.connect()
logger.info("Connected to radio")
-2
View File
@@ -724,7 +724,6 @@ class MessageRepository:
"""
SELECT m.conversation_key,
COUNT(*) as unread_count,
MAX(m.received_at) as last_message_time,
SUM(CASE
WHEN ? <> '' AND INSTR(LOWER(m.text), LOWER(?)) > 0 THEN 1
ELSE 0
@@ -749,7 +748,6 @@ class MessageRepository:
"""
SELECT m.conversation_key,
COUNT(*) as unread_count,
MAX(m.received_at) as last_message_time,
SUM(CASE
WHEN ? <> '' AND INSTR(LOWER(m.text), LOWER(?)) > 0 THEN 1
ELSE 0
-3
View File
@@ -8,7 +8,6 @@ from pydantic import BaseModel, Field
from app.dependencies import require_connected
from app.models import Channel
from app.radio import radio_manager
from app.radio_sync import ensure_default_channels
from app.repository import ChannelRepository
logger = logging.getLogger(__name__)
@@ -26,8 +25,6 @@ class CreateChannelRequest(BaseModel):
@router.get("", response_model=list[Channel])
async def list_channels() -> list[Channel]:
"""List all channels from the database."""
# Ensure Public channel always exists (self-healing)
await ensure_default_channels()
return await ChannelRepository.get_all()
+4 -1
View File
@@ -1,5 +1,6 @@
import logging
from hashlib import sha256
from sqlite3 import OperationalError
import aiosqlite
from fastapi import APIRouter, BackgroundTasks
@@ -288,7 +289,9 @@ async def run_maintenance(request: MaintenanceRequest) -> MaintenanceResult:
await vacuum_conn.executescript("VACUUM;")
vacuumed = True
logger.info("Database vacuumed")
except Exception as e:
except OperationalError as e:
logger.warning("VACUUM skipped (database busy): %s", e)
except Exception as e:
logger.error("VACUUM failed unexpectedly: %s", e)
return MaintenanceResult(packets_deleted=deleted, vacuumed=vacuumed)