refactor: replace issues backend with milestone tasks
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import Any, Dict, Tuple
|
||||
import requests
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.models import Issue
|
||||
from app.models.task import Task, TaskStatus
|
||||
from app.models.monitor import ProviderAccount, ProviderUsageSnapshot, MonitoredServer, ServerState
|
||||
|
||||
_CACHE: Dict[str, Dict[str, Any]] = {}
|
||||
@@ -70,25 +70,25 @@ def _normalize_usage_payload(payload: Dict[str, Any]) -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def get_issue_stats_cached(db: Session, ttl_seconds: int = 1800):
|
||||
key = 'issue_stats_24h'
|
||||
def get_task_stats_cached(db: Session, ttl_seconds: int = 1800):
|
||||
key = 'task_stats_24h'
|
||||
now = _now()
|
||||
hit = _CACHE.get(key)
|
||||
if hit and (now - hit['at']).total_seconds() < ttl_seconds:
|
||||
return hit['data']
|
||||
|
||||
since = now - timedelta(hours=24)
|
||||
total = db.query(Issue).count()
|
||||
new_24h = db.query(Issue).filter(Issue.created_at >= since).count()
|
||||
processed_24h = db.query(Issue).filter(
|
||||
Issue.updated_at != None,
|
||||
Issue.updated_at >= since,
|
||||
Issue.status.in_(['resolved', 'closed'])
|
||||
total = db.query(Task).count()
|
||||
new_24h = db.query(Task).filter(Task.created_at >= since).count()
|
||||
processed_24h = db.query(Task).filter(
|
||||
Task.updated_at != None,
|
||||
Task.updated_at >= since,
|
||||
Task.status == TaskStatus.CLOSED,
|
||||
).count()
|
||||
data = {
|
||||
'total_issues': total,
|
||||
'new_issues_24h': new_24h,
|
||||
'processed_issues_24h': processed_24h,
|
||||
'total_tasks': total,
|
||||
'new_tasks_24h': new_24h,
|
||||
'processed_tasks_24h': processed_24h,
|
||||
'computed_at': now.isoformat(),
|
||||
'cache_ttl_seconds': ttl_seconds,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user