完善查询历史记录
This commit is contained in:
@@ -2736,8 +2736,16 @@ async function loadHistoryResults(historyId) {
|
||||
// 设置当前结果数据
|
||||
currentResults = result.data;
|
||||
|
||||
// 确保必要的数组字段存在
|
||||
if (!currentResults.differences) currentResults.differences = [];
|
||||
if (!currentResults.identical_results) currentResults.identical_results = [];
|
||||
if (!currentResults.raw_pro_data) currentResults.raw_pro_data = [];
|
||||
if (!currentResults.raw_test_data) currentResults.raw_test_data = [];
|
||||
if (!currentResults.field_diff_count) currentResults.field_diff_count = {};
|
||||
if (!currentResults.summary) currentResults.summary = {};
|
||||
|
||||
// 根据查询类型设置分表模式
|
||||
if (result.data.history_info.query_type === 'sharding') {
|
||||
if (result.data.history_info && result.data.history_info.query_type === 'sharding') {
|
||||
isShardingMode = true;
|
||||
document.getElementById('enableSharding').checked = true;
|
||||
toggleShardingMode();
|
||||
@@ -2752,14 +2760,18 @@ async function loadHistoryResults(historyId) {
|
||||
|
||||
// 关闭历史记录modal
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('queryHistoryModal'));
|
||||
modal.hide();
|
||||
if (modal) {
|
||||
modal.hide();
|
||||
}
|
||||
|
||||
const queryTypeDesc = result.data.history_info.query_type === 'sharding' ? '分表查询' : '单表查询';
|
||||
showAlert('success', `${queryTypeDesc}历史记录结果 "${result.data.history_info.name}" 加载成功`);
|
||||
const queryTypeDesc = (result.data.history_info && result.data.history_info.query_type === 'sharding') ? '分表查询' : '单表查询';
|
||||
const historyName = (result.data.history_info && result.data.history_info.name) || '未知';
|
||||
showAlert('success', `${queryTypeDesc}历史记录结果 "${historyName}" 加载成功`);
|
||||
} else {
|
||||
showAlert('danger', result.error || '加载历史记录结果失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载历史记录结果失败:', error);
|
||||
showAlert('danger', '加载历史记录结果失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
@@ -3173,7 +3185,7 @@ let allQueryLogs = []; // 存储所有日志
|
||||
|
||||
async function refreshQueryLogs() {
|
||||
try {
|
||||
const response = await fetch('/api/query-logs?grouped=true');
|
||||
const response = await fetch('/api/query-logs?grouped=true&from_db=true');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success && result.data) {
|
||||
@@ -3366,19 +3378,19 @@ function filterLogsByLevel() {
|
||||
}
|
||||
|
||||
async function clearQueryLogs() {
|
||||
if (!confirm('确定要清空所有查询日志吗?')) {
|
||||
if (!confirm('确定要清空所有查询日志吗?这将删除内存和数据库中的所有日志记录。')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/query-logs', {
|
||||
const response = await fetch('/api/query-logs?clear_db=true', {
|
||||
method: 'DELETE'
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
document.getElementById('query-logs').innerHTML = '<div class="alert alert-info">查询日志已清空</div>';
|
||||
showAlert('success', '查询日志已清空');
|
||||
showAlert('success', result.message);
|
||||
} else {
|
||||
showAlert('danger', '清空查询日志失败: ' + result.error);
|
||||
}
|
||||
@@ -3388,6 +3400,47 @@ async function clearQueryLogs() {
|
||||
}
|
||||
}
|
||||
|
||||
// 清理旧日志
|
||||
async function cleanupOldLogs() {
|
||||
const days = prompt('请输入要保留的天数(默认30天):', '30');
|
||||
if (days === null) return; // 用户取消
|
||||
|
||||
const daysToKeep = parseInt(days) || 30;
|
||||
if (daysToKeep <= 0) {
|
||||
showAlert('warning', '保留天数必须大于0');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm(`确定要清理超过 ${daysToKeep} 天的旧日志吗?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/query-logs/cleanup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
days_to_keep: daysToKeep
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('success', result.message);
|
||||
// 刷新日志显示
|
||||
refreshQueryLogs();
|
||||
} else {
|
||||
showAlert('danger', '清理旧日志失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('清理旧日志失败:', error);
|
||||
showAlert('danger', '清理旧日志失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 在查询执行后自动刷新日志
|
||||
function autoRefreshLogsAfterQuery() {
|
||||
// 延迟一下确保后端日志已经记录
|
||||
|
Reference in New Issue
Block a user