|
|
@@ -20,6 +20,22 @@ class DatabaseManager:
|
|
|
return self.SessionLocal()
|
|
|
|
|
|
|
|
|
+class DatabaseManager2:
|
|
|
+ """数据库管理类"""
|
|
|
+
|
|
|
+ # mysql+pymysql://<用户名>:<密码>@<主机地址>:<端口>/<数据库名>?charset=utf8mb4
|
|
|
+ def __init__(self):
|
|
|
+ connection_string = (
|
|
|
+ f"mysql+pymysql://content_rw:bC1aH4bA1lB0@rm-t4nh1xx6o2a6vj8qu3o.mysql.singapore.rds.aliyuncs.com:3306/open_aigc_pattern?charset=utf8mb4"
|
|
|
+ )
|
|
|
+ self.engine = create_engine(connection_string, pool_pre_ping=True, pool_recycle=3600)
|
|
|
+ self.SessionLocal = sessionmaker(bind=self.engine, autoflush=False, autocommit=False)
|
|
|
+
|
|
|
+ def get_session(self) -> Session:
|
|
|
+ """获取数据库会话"""
|
|
|
+ return self.SessionLocal()
|
|
|
+
|
|
|
+
|
|
|
def query_video_ids_by_names(execution_id: int, names: Iterable[str]) -> list[str]:
|
|
|
"""按 execution_id + 名称列表查询去重后的 post_id。"""
|
|
|
clean_names = [str(n).strip() for n in names if n is not None and str(n).strip()]
|
|
|
@@ -76,3 +92,24 @@ def query_video_ids_by_names(execution_id: int, names: Iterable[str]) -> list[st
|
|
|
|
|
|
return list(video_ids)
|
|
|
|
|
|
+
|
|
|
+db2 = DatabaseManager2()
|
|
|
+
|
|
|
+
|
|
|
+def exist_cluster_tree(merge_level2):
|
|
|
+ session = db2.get_session()
|
|
|
+
|
|
|
+ exec_row = session.execute(
|
|
|
+ text("""
|
|
|
+ SELECT id
|
|
|
+ FROM cluster_execution
|
|
|
+ WHERE name LIKE :name AND status = 2
|
|
|
+ ORDER BY create_time DESC
|
|
|
+ LIMIT 1
|
|
|
+ """),
|
|
|
+ {"name": f"{merge_level2}%"},
|
|
|
+ ).mappings().first()
|
|
|
+
|
|
|
+ if not exec_row:
|
|
|
+ return False
|
|
|
+ return True
|