From 10baa22acb808317eb56e0d9e674d642c0707455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Fri, 21 Aug 2026 11:26:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(media):=20tried=E9=9B=86=E5=90=88=E5=88=86?= =?UTF-8?q?=E7=89=87=E8=BF=9BNOT=20IN(3=E4=B8=87+msg=5Fid=E8=B6=85SQLite?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E4=B8=8A=E9=99=90,42k=E5=90=8E=E5=B4=A9;?= =?UTF-8?q?=E6=AF=8F=E6=99=9A=E5=85=A8=E9=87=8F=E5=AA=92=E4=BD=93=E6=AD=A5?= =?UTF-8?q?=E5=90=8Cbug)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- yunke-server/app/scraper/media.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/yunke-server/app/scraper/media.py b/yunke-server/app/scraper/media.py index 6c0c727..ba83044 100644 --- a/yunke-server/app/scraper/media.py +++ b/yunke-server/app/scraper/media.py @@ -478,7 +478,13 @@ async def download_message_images( .limit(batch_size) ) if tried: - stmt = stmt.where(Message.msg_id.not_in(tried)) + # 分片进 NOT IN —— 单次塞全部 tried(3万+)会超 SQLite 变量上限 + # (默认 32766/999),2026-08-20 实测 42k 后崩;每次最多 500 个。 + tried_list = list(tried) + conds = [] + for i in range(0, len(tried_list), 500): + conds.append(Message.msg_id.not_in(tried_list[i:i + 500])) + stmt = stmt.where(sa.and_(*conds)) rows = (await session.execute(stmt)).all() if not rows: break