From be50d6c555e9a59c6d26c89125fb2e97f9e26601 Mon Sep 17 00:00:00 2001 From: claude_dev Date: Wed, 26 Aug 2026 06:37:33 +0800 Subject: [PATCH] =?UTF-8?q?perf(factor):=20universe=20parquet=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E2=80=94=E2=80=94=E5=A4=96=E9=83=A8~20min=E6=9D=80?= =?UTF-8?q?=E6=89=8B=20regime=E4=B8=8B=E6=AF=8F=E6=9D=A1=E5=91=BD15min?= =?UTF-8?q?=E5=86=B7=E5=8A=A0=E8=BD=BD=E7=BF=BB=E8=BD=AC=E4=B8=BA=E7=A7=92?= =?UTF-8?q?=E7=BA=A7=E5=A4=8D=E8=BD=BD,20min=E5=AF=BF=E5=91=BD=3D=E7=BA=AF?= =?UTF-8?q?=E8=AE=A1=E7=AE=9715-20=E5=9B=A0=E5=AD=90;key=E5=90=AB=E7=AA=97?= =?UTF-8?q?=E5=8F=A3/symbols/limit=E9=98=B2=E4=B8=B2=E6=B1=A0,=E5=86=99?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=9D=99=E9=BB=98=20[vps]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanguo_factor/universe.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sanguo_factor/universe.py b/sanguo_factor/universe.py index 8ebd309..5493cf9 100644 --- a/sanguo_factor/universe.py +++ b/sanguo_factor/universe.py @@ -35,6 +35,16 @@ def load_universe_bars( datetime.strptime(end, "%Y-%m-%d") + timedelta(days=_FORWARD_DAYS) ).strftime("%Y-%m-%d") + # 缓存短路:含窗口/symbols/limit防串池 + import os as _os + cache_path = _os.path.join( + _os.path.dirname(_os.path.abspath(vnpy_db)), + f"universe_cache_{start}_{end}_{len(symbols) if symbols else 'all'}" + f"{'_'+str(limit) if limit else ''}.parquet" + ) + if _os.path.exists(cache_path): + return pl.read_parquet(cache_path) + if symbols is None: conn = sqlite3.connect(vnpy_db, timeout=60) try: @@ -100,6 +110,13 @@ def load_universe_bars( .with_columns(pl.int_range(pl.len()).over("vt_symbol").alias("bar_idx")) .collect() ) + + # 写缓存(失败静默,不影响主流程) + try: + df.write_parquet(cache_path) + except Exception: + pass + return df