Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: Remove unnecessary metrics cache warming

LearningCircuitf4b1959af529
diff --git a/src/local_deep_research/memory_cache/warmup.py b/src/local_deep_research/memory_cache/warmup.py
index 28f54802dc..53b1a3bebe 100644
--- a/src/local_deep_research/memory_cache/warmup.py
+++ b/src/local_deep_research/memory_cache/warmup.py
@@ -1,7 +1,8 @@
-"""Cache warming strategies for settings and metrics.
+"""Cache warming strategies for settings and API keys.
This module implements non-blocking cache warming for user login
-and application startup scenarios.
+and application startup scenarios. Metrics are intentionally not cached
+as they change frequently and are better served directly from the database.
"""
import asyncio
@@ -11,7 +12,7 @@ from concurrent.futures import ThreadPoolExecutor
from loguru import logger
from .config import get_thread_local_cache, cache_user_data
-from ..database.models import UserSettings, APIKey, TokenUsage, SearchCall
+from ..database.models import UserSettings, APIKey
from ..database.session_context import get_user_db_session
@@ -63,7 +64,7 @@ class CacheWarmer:
cache_types: Optional list of cache types to warm
"""
if cache_types is None:
- cache_types = ["settings", "api_keys", "metrics"]
+ cache_types = ["settings", "api_keys"]
# Create background task
loop = asyncio.get_event_loop()
@@ -88,9 +89,6 @@ class CacheWarmer:
if "api_keys" in cache_types:
self._warm_user_api_keys(session, user_id)
- if "metrics" in cache_types:
- self._warm_user_metrics(session, user_id)
-
except Exception as e:
logger.error(f"Cache warming failed for user {user_id}: {e}")
@@ -146,46 +144,6 @@ class CacheWarmer:
except Exception as e:
logger.error(f"Failed to warm API keys for user {user_id}: {e}")
- def _warm_user_metrics(self, session, user_id: str) -> None:
- """Warm user metrics aggregations."""
- try:
- # Warm recent token usage (no user_id filter needed)
- recent_usage = (
- session.query(TokenUsage.model_name, TokenUsage.total_tokens)
- .order_by(TokenUsage.created_at.desc())
- .limit(100)
- .all()
- )
-
- self.cache.set(
- user_id,
- "metrics",
- "recent_token_usage",
- recent_usage,
- expiration_time=300, # 5 minutes
- )
-
- # Warm search metrics (no user_id filter needed)
- search_metrics = (
- session.query(SearchCall.search_engine, SearchCall.success)
- .order_by(SearchCall.created_at.desc())
- .limit(100)
- .all()
- )
-
- self.cache.set(
- user_id,
- "metrics",
- "recent_searches",
- search_metrics,
- expiration_time=300,
- )
-
- logger.debug(f"Warmed metrics for user {user_id}")
-
- except Exception as e:
- logger.error(f"Failed to warm metrics for user {user_id}: {e}")
-
async def _warm_system_configs(self) -> None:
"""Warm system-wide configurations."""
# This would warm shared configurations
@@ -229,9 +187,7 @@ class ProgressiveCacheWarmer(CacheWarmer):
priority_order = [
"settings:frequently_used",
"api_keys:active",
- "metrics:summary",
"settings:all",
- "metrics:detailed",
]
for cache_type in priority_order: