mirror of
https://github.com/stardrophere/InsightRadar.git
synced 2026-06-05 23:56:36 +08:00
optimize+注释
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
"""
|
||||
用户偏好模块:兴趣关键词的增删查、基于关键词的个性化事件推荐
|
||||
"""
|
||||
import time
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
@@ -140,7 +143,7 @@ def recommend_events(
|
||||
"""基于用户兴趣词推荐事件(精确匹配 + 语义匹配)。"""
|
||||
_ensure_self_access(user_id, current_user)
|
||||
|
||||
# --- 1. 尝试从缓存读取 ---
|
||||
# 推荐结果缓存,避免频繁调用匹配服务
|
||||
cache_key = f"{user_id}:{min_hot}:{hours}:{limit}:{semantic_threshold}:{sort_by}"
|
||||
current_time = time.time()
|
||||
|
||||
@@ -184,7 +187,7 @@ def recommend_events(
|
||||
data=result_data,
|
||||
)
|
||||
|
||||
# --- 2. 写入缓存 ---
|
||||
# 写入缓存,超过 2000 条时清空防止内存膨胀
|
||||
if len(_RECOMMEND_CACHE) > 2000:
|
||||
# 防止内存无限增长
|
||||
_RECOMMEND_CACHE.clear()
|
||||
|
||||
Reference in New Issue
Block a user