perf: 6项性能与正确性优化
1. get_stock_name: 延迟批量保存缓存(60秒去抖),避免每次新缓存都写文件 2. get_stock_name: 优先从DB stock_realtime_price查name,未命中再调腾讯API 3. compute_comprehensive_score: 单股模式也使用_fund_flow_cache(30分钟TTL) 4. _get_kline_from_local_db: 移除conn.autocommit=True,避免污染连接池事务模式 5. deep_analyze: K线天数从180改为120,与实时检测统一 6. detect_all_signals: 已有指标列时跳过重复calc_all_indicators
This commit is contained in:
@@ -134,10 +134,16 @@ def compute_comprehensive_score(stock_code, stock_name, technical_score, df=None
|
||||
external_score = 0
|
||||
summaries = []
|
||||
|
||||
# ---- P0: 主力资金进出 ----
|
||||
# ---- P0: 主力资金进出(带30分钟缓存,与批量模式一致)----
|
||||
try:
|
||||
from services.fund_flow_analyzer import analyze_fund_flow
|
||||
fund_result = analyze_fund_flow(stock_code, days=5)
|
||||
now = time.time()
|
||||
cached_ff = _fund_flow_cache.get(stock_code)
|
||||
if cached_ff and (now - cached_ff[1]) < _FUND_FLOW_TTL:
|
||||
fund_result = cached_ff[0]
|
||||
else:
|
||||
from services.fund_flow_analyzer import analyze_fund_flow
|
||||
fund_result = analyze_fund_flow(stock_code, days=5)
|
||||
_fund_flow_cache[stock_code] = (fund_result, now)
|
||||
factors['fund_flow'] = fund_result
|
||||
external_score += fund_result.get('score', 0)
|
||||
all_reasons.extend(fund_result.get('reasons', []))
|
||||
|
||||
Reference in New Issue
Block a user