refactor: 清理调试日志和优化代码

- 移除outfit_image_commands.rs中的调试println语句
- 移除outfitImageService.ts中的调试console.log语句
- 优化outfit_image_repository.rs代码结构
- 改进connection_pool.rs连接管理

提升代码质量,减少不必要的日志输出。
This commit is contained in:
imeepos 2025-07-30 23:40:27 +08:00
parent 68c0ff9469
commit 5e92c47835
4 changed files with 0 additions and 31 deletions

View File

@ -23,7 +23,6 @@ impl OutfitImageRepository {
/// 初始化数据库表(强制使用连接池)
pub fn init_tables(&self) -> Result<()> {
println!("🏊 使用连接池初始化穿搭图片表...");
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -99,7 +98,6 @@ impl OutfitImageRepository {
[],
).map_err(|e| anyhow!("创建索引失败: {}", e))?;
println!("✅ 穿搭图片表初始化完成");
pooled_conn.execute(
"CREATE INDEX IF NOT EXISTS idx_outfit_image_records_status ON outfit_image_records (status)",
@ -160,7 +158,6 @@ impl OutfitImageRepository {
/// 在事务中创建记录和商品图片(强制使用连接池)
pub fn create_record_with_products(&self, record: &OutfitImageRecord) -> Result<()> {
println!("🏊 强制使用连接池创建记录...");
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -191,7 +188,6 @@ impl OutfitImageRepository {
}
// 如果重试失败,使用阻塞方式获取连接池连接
println!("🚨 重试失败,使用阻塞方式获取连接池连接...");
match self.database.acquire_from_pool() {
Ok(pooled_conn) => {
println!("✅ 阻塞方式获取连接池连接成功");
@ -205,7 +201,6 @@ impl OutfitImageRepository {
/// 使用连接池连接执行操作
fn execute_with_pooled_connection(&self, record: &OutfitImageRecord, pooled_conn: crate::infrastructure::connection_pool::PooledConnectionHandle) -> Result<()> {
println!("📝 使用连接池连接创建记录...");
// 开始事务
let tx = pooled_conn.unchecked_transaction().map_err(|e| anyhow!("开始事务失败: {}", e))?;
@ -215,13 +210,11 @@ impl OutfitImageRepository {
// 提交事务
tx.commit().map_err(|e| anyhow!("提交事务失败: {}", e))?;
println!("✅ 连接池事务提交成功");
Ok(())
}
/// 使用连接句柄执行操作
fn execute_with_connection_handle(&self, record: &OutfitImageRecord, conn_handle: crate::infrastructure::database::ConnectionHandle) -> Result<()> {
println!("📝 使用连接句柄创建记录...");
// 开始事务
let tx = conn_handle.unchecked_transaction().map_err(|e| anyhow!("开始事务失败: {}", e))?;
@ -231,7 +224,6 @@ impl OutfitImageRepository {
// 提交事务
tx.commit().map_err(|e| anyhow!("提交事务失败: {}", e))?;
println!("✅ 连接句柄事务提交成功");
Ok(())
}
@ -276,7 +268,6 @@ impl OutfitImageRepository {
/// 通用事务执行方法
fn execute_transaction_with_tx(&self, record: &OutfitImageRecord, tx: &rusqlite::Transaction) -> Result<()> {
println!("📝 创建主记录...");
// 创建主记录
let result_urls_json = serde_json::to_string(&record.result_urls)
.map_err(|e| anyhow!("序列化result_urls失败: {}", e))?;
@ -307,7 +298,6 @@ impl OutfitImageRepository {
println!("📷 创建商品图片记录,共 {} 个...", record.product_images.len());
// 创建商品图片记录
for (index, product_image) in record.product_images.iter().enumerate() {
println!("📷 创建商品图片 {}/{}", index + 1, record.product_images.len());
tx.execute(
r#"
INSERT INTO product_images (
@ -328,14 +318,12 @@ impl OutfitImageRepository {
).map_err(|e| anyhow!("创建商品图片失败: {}", e))?;
}
println!("💾 事务准备提交...");
Ok(())
}
/// 更新穿搭图片生成记录(强制使用连接池)
pub fn update_record(&self, record: &OutfitImageRecord) -> Result<()> {
println!("🏊 使用连接池更新穿搭记录: {}", &record.id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -367,7 +355,6 @@ impl OutfitImageRepository {
],
).map_err(|e| anyhow!("更新穿搭图片记录失败: {}", e))?;
println!("✅ 穿搭记录更新完成");
Ok(())
}
@ -409,7 +396,6 @@ impl OutfitImageRepository {
/// 根据模特ID获取穿搭图片生成记录列表强制使用连接池
pub fn get_records_by_model_id(&self, model_id: &str) -> Result<Vec<OutfitImageRecord>> {
println!("🏊 使用连接池获取模特穿搭记录: {}", &model_id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -453,13 +439,11 @@ impl OutfitImageRepository {
records.push(record);
}
println!("✅ 连接池查询完成,获取到 {} 条记录", records.len());
Ok(records)
}
/// 删除穿搭图片生成记录(强制使用连接池)
pub fn delete_record(&self, id: &str) -> Result<()> {
println!("🏊 使用连接池删除穿搭记录: {}", &id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -474,13 +458,11 @@ impl OutfitImageRepository {
params![id],
).map_err(|e| anyhow!("删除穿搭图片记录失败: {}", e))?;
println!("✅ 连接池删除穿搭记录完成");
Ok(())
}
/// 创建商品图片(强制使用连接池)
pub fn create_product_image(&self, product_image: &ProductImage) -> Result<()> {
println!("🏊 使用连接池创建商品图片: {}", &product_image.id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -509,13 +491,11 @@ impl OutfitImageRepository {
],
).map_err(|e| anyhow!("创建商品图片失败: {}", e))?;
println!("✅ 连接池创建商品图片完成");
Ok(())
}
/// 根据记录ID获取商品图片列表强制使用连接池
pub fn get_product_images_by_record_id(&self, record_id: &str) -> Result<Vec<ProductImage>> {
println!("🏊 使用连接池获取商品图片: {}", &record_id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -544,13 +524,11 @@ impl OutfitImageRepository {
images.push(image.map_err(|e| anyhow!("解析商品图片失败: {}", e))?);
}
println!("✅ 连接池查询商品图片完成,获取到 {} 张图片", images.len());
Ok(images)
}
/// 创建穿搭图片(强制使用连接池)
pub fn create_outfit_image(&self, outfit_image: &OutfitImage) -> Result<()> {
println!("🏊 使用连接池创建穿搭图片: {}", &outfit_image.id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -583,13 +561,11 @@ impl OutfitImageRepository {
],
).map_err(|e| anyhow!("创建穿搭图片失败: {}", e))?;
println!("✅ 连接池创建穿搭图片完成");
Ok(())
}
/// 根据记录ID获取穿搭图片列表强制使用连接池
pub fn get_outfit_images_by_record_id(&self, record_id: &str) -> Result<Vec<OutfitImage>> {
println!("🏊 使用连接池获取穿搭图片: {}", &record_id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -618,13 +594,11 @@ impl OutfitImageRepository {
images.push(image.map_err(|e| anyhow!("解析穿搭图片失败: {}", e))?);
}
println!("✅ 连接池查询穿搭图片完成,获取到 {} 张图片", images.len());
Ok(images)
}
/// 获取模特的穿搭图片统计信息(强制使用连接池)
pub fn get_stats_by_model_id(&self, model_id: &str) -> Result<OutfitImageStats> {
println!("🏊 使用连接池获取穿搭统计: {}", &model_id[..8]);
// 🚨 强制使用连接池,避免死锁
if !self.database.has_pool() {
@ -677,7 +651,6 @@ impl OutfitImageRepository {
))
}).map_err(|e| anyhow!("查询图片统计失败: {}", e))?;
println!("✅ 连接池查询穿搭统计完成: 记录{}条, 图片{}", total_records, total_images);
Ok(OutfitImageStats {
total_records,
total_images,

View File

@ -277,8 +277,6 @@ impl ConnectionPool {
stats.total_returned += 1;
stats.active_connections = stats.active_connections.saturating_sub(1);
stats.idle_connections += 1;
println!("连接已归还到池中,当前连接数: {}", connections.len());
}
/// 获取连接池统计信息

View File

@ -101,7 +101,6 @@ pub async fn get_model_dashboard_stats(
average_generation_time_ms,
};
println!("✅ 模特个人看板统计信息获取成功");
Ok(dashboard_stats)
}

View File

@ -23,7 +23,6 @@ export class OutfitImageService {
modelId
});
console.log('✅ 模特个人看板统计信息获取成功:', stats);
return stats;
} catch (error) {
console.error('❌ 获取模特个人看板统计信息失败:', error);