mirror of
https://github.com/stardrophere/InsightRadar.git
synced 2026-06-05 23:56:36 +08:00
update
This commit is contained in:
@@ -30,7 +30,8 @@ MAX_RANKING_POINTS = 30
|
||||
@router.get("/unified", response_model=PaginatedUnifiedEventResponse)
|
||||
def list_unified_events(
|
||||
min_hot: int = Query(5, ge=0, description="热度阈值,仅返回 hot_score >= 此值的事件"),
|
||||
hours: int = Query(24, ge=1, le=720, description="查询最近多少小时的数据"),
|
||||
hours: int = Query(48, ge=1, le=720, description="查询最近多少小时的数据"),
|
||||
sort_by: str = Query("hot_score", description="排序字段: hot_score | created_at"),
|
||||
skip: int = Query(0, ge=0, description="分页偏移量"),
|
||||
limit: int = Query(10, ge=1, le=50, description="每页返回条数"),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -46,13 +47,12 @@ def list_unified_events(
|
||||
total = base_query.count()
|
||||
|
||||
# 分页查询
|
||||
events = (
|
||||
base_query
|
||||
.order_by(UnifiedEvent.hot_score.desc())
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
if sort_by == "created_at":
|
||||
base_query = base_query.order_by(UnifiedEvent.created_at.desc())
|
||||
else:
|
||||
base_query = base_query.order_by(UnifiedEvent.hot_score.desc(), UnifiedEvent.created_at.desc())
|
||||
|
||||
events = base_query.offset(skip).limit(limit).all()
|
||||
|
||||
if not events:
|
||||
return PaginatedUnifiedEventResponse(total=total, has_more=False, data=[])
|
||||
@@ -110,7 +110,8 @@ def list_unified_events(
|
||||
results: list[UnifiedEventResponse] = []
|
||||
for ev in events:
|
||||
platform_list: list[PlatformTrendResponse] = []
|
||||
for trend, source_name in trend_map.get(ev.id, []):
|
||||
trends_for_ev = trend_map.get(ev.id, [])
|
||||
for trend, source_name in trends_for_ev:
|
||||
history = ranking_map.get(trend.id, [])
|
||||
# 截取尾部,只保留最近的点
|
||||
if len(history) > MAX_RANKING_POINTS:
|
||||
@@ -127,6 +128,13 @@ def list_unified_events(
|
||||
)
|
||||
)
|
||||
|
||||
# 取所有关联热搜条目中最新的 updated_at,代表"最后一次在平台热搜榜看到"的时间
|
||||
last_active_at = (
|
||||
max(t.updated_at for t, _ in trends_for_ev)
|
||||
if trends_for_ev
|
||||
else ev.updated_at
|
||||
)
|
||||
|
||||
results.append(
|
||||
UnifiedEventResponse(
|
||||
event_id=ev.id,
|
||||
@@ -134,6 +142,7 @@ def list_unified_events(
|
||||
summary=ev.ai_comprehensive_summary,
|
||||
hot_score=ev.hot_score,
|
||||
created_at=ev.created_at,
|
||||
last_active_at=last_active_at,
|
||||
platforms=platform_list,
|
||||
tags=tag_map.get(ev.id, []),
|
||||
)
|
||||
@@ -204,12 +213,19 @@ def get_unified_event(
|
||||
)
|
||||
)
|
||||
|
||||
last_active_at = (
|
||||
max(t.updated_at for t, _ in trend_rows)
|
||||
if trend_rows
|
||||
else ev.updated_at
|
||||
)
|
||||
|
||||
return UnifiedEventResponse(
|
||||
event_id=ev.id,
|
||||
unified_title=ev.unified_title if ev.unified_title else "暂无标题",
|
||||
summary=ev.ai_comprehensive_summary,
|
||||
hot_score=ev.hot_score,
|
||||
created_at=ev.created_at,
|
||||
last_active_at=last_active_at,
|
||||
platforms=platform_list,
|
||||
tags=tags,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user