优化 素材库新增处理优化,提速,其余bug处理

This commit is contained in:
Chen committed 2025-12-04 10:57:50 +08:00
1 parent ad774d8a22
commit 4bce6f5d72
67 files changed
+4861 -3111

No files matched your search

+12 -27
View File
@@ -24,15 +24,9 @@ class MemoryMonitor {
* Start monitoring memory usage
*/
start() {
if (this.isRunning) {
console.log('[MemoryMonitor] Already running');
return;
}
if (this.isRunning) return;
console.log('[MemoryMonitor] Starting memory monitoring');
console.log(` Warning threshold: ${(this.warningThreshold / 1024 / 1024).toFixed(0)}MB`);
console.log(` Danger threshold: ${(this.dangerThreshold / 1024 / 1024).toFixed(0)}MB`);
console.log(` Check interval: ${this.checkInterval}ms`);
console.log('📊 内存监控已启动');
this.isRunning = true;
@@ -43,7 +37,6 @@ class MemoryMonitor {
// Start development mode logging
if (this.devMode) {
console.log('[MemoryMonitor] Development mode: logging every 30 seconds');
this.devLogIntervalId = setInterval(() => {
const stats = this.getMemoryStats();
this.logMemoryStats(stats, 'DEV');
@@ -58,11 +51,9 @@ class MemoryMonitor {
* Stop monitoring
*/
stop() {
if (!this.isRunning) {
return;
}
if (!this.isRunning) return;
console.log('[MemoryMonitor] Stopping memory monitoring');
console.log('📊 内存监控已停止');
if (this.intervalId) {
clearInterval(this.intervalId);
@@ -125,7 +116,7 @@ class MemoryMonitor {
this.lastWarningTime = now;
console.warn('[MemoryMonitor] ⚠️ WARNING: Memory usage high');
console.warn('⚠️ 内存使用偏高');
this.logMemoryStats(stats, 'WARNING');
}
@@ -142,12 +133,12 @@ class MemoryMonitor {
this.lastDangerTime = now;
console.error('[MemoryMonitor] 🚨 DANGER: Memory usage critical!');
console.error('🚨 内存使用危险!');
this.logMemoryStats(stats, 'DANGER');
// Trigger emergency cleanup if cleanup manager is available
if (this.cleanupManager) {
console.log('[MemoryMonitor] Triggering emergency cleanup...');
console.log('🚨 触发紧急清理...');
try {
this.cleanupManager.executeEmergencyCleanup();
@@ -155,11 +146,9 @@ class MemoryMonitor {
setTimeout(() => {
const afterStats = this.getMemoryStats();
const afterRSS = afterStats.rss / 1024 / 1024;
console.log(`[MemoryMonitor] After emergency cleanup: RSS = ${afterRSS.toFixed(0)}MB`);
// 如果 RSS 仍然很高,强制更多 GC
if (afterRSS > 500) {
console.log('[MemoryMonitor] RSS still high, forcing additional GC...');
if (global.gc) {
for (let i = 0; i < 10; i++) {
global.gc();
@@ -168,10 +157,8 @@ class MemoryMonitor {
}
}, 1000);
} catch (error) {
console.error('[MemoryMonitor] Emergency cleanup failed:', error);
console.error('❌ 紧急清理失败:', error.message);
}
} else {
console.warn('[MemoryMonitor] No cleanup manager available');
}
}
@@ -185,12 +172,10 @@ class MemoryMonitor {
const externalMB = (stats.external / 1024 / 1024).toFixed(2);
const arrayBuffersMB = (stats.arrayBuffers / 1024 / 1024).toFixed(2);
console.log(`[MemoryMonitor] ${level} - Memory Statistics:`);
console.log(` Heap Used: ${heapUsedMB} MB`);
console.log(` Heap Total: ${heapTotalMB} MB`);
console.log(` RSS: ${rssMB} MB`);
console.log(` External: ${externalMB} MB`);
console.log(` Array Buffers: ${arrayBuffersMB} MB`);
console.log(`📊 内存状态 [${level}]:`);
console.log(` Heap: ${heapUsedMB}/${heapTotalMB} MB`);
console.log(` RSS: ${rssMB} MB`);
console.log(` External: ${externalMB} MB`);
}
/**