|
@@ -57,8 +57,33 @@ def compress_image_if_needed(file_path, max_dim=2000):
|
|
|
print(f"Warning: Image compression/normalization failed for {file_path}: {e}")
|
|
print(f"Warning: Image compression/normalization failed for {file_path}: {e}")
|
|
|
return file_path
|
|
return file_path
|
|
|
|
|
|
|
|
-def get_db_connection():
|
|
|
|
|
- return pymysql.connect(**DB_CONFIG)
|
|
|
|
|
|
|
+# 尝试使用数据库连接池,如果不可用则使用普通连接
|
|
|
|
|
+try:
|
|
|
|
|
+ from DBUtils.PooledDB import PooledDB
|
|
|
|
|
+ # 创建连接池
|
|
|
|
|
+ pool = PooledDB(
|
|
|
|
|
+ creator=pymysql,
|
|
|
|
|
+ maxconnections=10, # 连接池最大连接数
|
|
|
|
|
+ mincached=2, # 初始化时创建的空闲连接数
|
|
|
|
|
+ maxcached=5, # 最大空闲连接数
|
|
|
|
|
+ maxshared=3, # 最大共享连接数
|
|
|
|
|
+ blocking=True, # 连接池满时是否阻塞等待
|
|
|
|
|
+ maxusage=None, # 一个连接最多被重复使用的次数
|
|
|
|
|
+ setsession=[], # 开始会话前执行的命令列表
|
|
|
|
|
+ ping=0, # 用ping命令检查连接是否可用的频率
|
|
|
|
|
+ **DB_CONFIG
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ def get_db_connection():
|
|
|
|
|
+ return pool.connection()
|
|
|
|
|
+
|
|
|
|
|
+ print("Database connection pool initialized successfully")
|
|
|
|
|
+except ImportError:
|
|
|
|
|
+ # 如果DBUtils不可用,使用普通连接
|
|
|
|
|
+ def get_db_connection():
|
|
|
|
|
+ return pymysql.connect(**DB_CONFIG)
|
|
|
|
|
+
|
|
|
|
|
+ print("DBUtils not available, using regular database connections")
|
|
|
|
|
|
|
|
def format_timestamp(ts):
|
|
def format_timestamp(ts):
|
|
|
if not ts: return '未知'
|
|
if not ts: return '未知'
|
|
@@ -1407,10 +1432,10 @@ def add_member():
|
|
|
if isinstance(content, list):
|
|
if isinstance(content, list):
|
|
|
updated = False
|
|
updated = False
|
|
|
if 0 <= idx < len(content):
|
|
if 0 <= idx < len(content):
|
|
|
- if not content[idx].get('is_imported'): # Avoid redundant updates
|
|
|
|
|
- content[idx]['is_imported'] = True
|
|
|
|
|
- content[idx]['imported_member_id'] = member_id
|
|
|
|
|
- updated = True
|
|
|
|
|
|
|
+ # Always update the status regardless of current value
|
|
|
|
|
+ content[idx]['is_imported'] = True
|
|
|
|
|
+ content[idx]['imported_member_id'] = member_id
|
|
|
|
|
+ updated = True
|
|
|
|
|
|
|
|
if updated:
|
|
if updated:
|
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
@@ -1568,10 +1593,10 @@ def edit_member(member_id):
|
|
|
if isinstance(content, list):
|
|
if isinstance(content, list):
|
|
|
updated = False
|
|
updated = False
|
|
|
if 0 <= idx < len(content):
|
|
if 0 <= idx < len(content):
|
|
|
- if not content[idx].get('is_imported'): # Avoid redundant updates
|
|
|
|
|
- content[idx]['is_imported'] = True
|
|
|
|
|
- content[idx]['imported_member_id'] = member_id
|
|
|
|
|
- updated = True
|
|
|
|
|
|
|
+ # Always update the status regardless of current value
|
|
|
|
|
+ content[idx]['is_imported'] = True
|
|
|
|
|
+ content[idx]['imported_member_id'] = member_id
|
|
|
|
|
+ updated = True
|
|
|
|
|
|
|
|
if updated:
|
|
if updated:
|
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
new_content = json.dumps(content, ensure_ascii=False)
|