refactor: 移除重算脚本部署,autocommit模式,2秒轮询

This commit is contained in:
2026-02-05 23:53:05 +08:00
parent 40b861ae3d
commit 76fcb106f3
4 changed files with 33 additions and 82 deletions

View File

@@ -65,7 +65,8 @@ class ImageSimilarityRecalc:
password=self.config.get('database', 'password'),
database=self.config.get('database', 'database'),
charset=self.config.get('database', 'charset'),
cursorclass=pymysql.cursors.DictCursor
cursorclass=pymysql.cursors.DictCursor,
autocommit=True
)
self.logger.info("数据库连接成功")
@@ -165,7 +166,6 @@ class ImageSimilarityRecalc:
WHERE id = %s
"""
cursor.execute(sql, (similar_id, score, image_id))
self.db_conn.commit()
self.logger.info(f"重复: {image_id} -> {similar_id} (分数={score:.4f})")
def update_as_unique(self, image_id: int):
@@ -179,7 +179,6 @@ class ImageSimilarityRecalc:
WHERE id = %s
"""
cursor.execute(sql, (image_id,))
self.db_conn.commit()
self.logger.info(f"不重复: {image_id} -> tag_extension")
def update_as_failed(self, image_id: int, reason: str):
@@ -191,7 +190,6 @@ class ImageSimilarityRecalc:
WHERE id = %s
"""
cursor.execute(sql, (image_id,))
self.db_conn.commit()
self.logger.warning(f"处理失败 {image_id}: {reason}")
def process_batch(self, image_records: List[dict]) -> Tuple[int, int, int]:
@@ -263,8 +261,8 @@ class ImageSimilarityRecalc:
images = self.get_recalc_images()
if not images:
self.logger.info("没有需要重新计算的图片,等待 10 秒后继续检查...")
time.sleep(10)
self.logger.info("没有需要重新计算的图片,等待 2 秒后继续检查...")
time.sleep(2)
continue
batch_num += 1