Skip to content

Commit edf597c

Browse files
committed
fix(stats): 修复命令统计数据膨胀问题
- weekly 模式下隐藏当前(不完整)周的数据 - 过滤 queue-operation 类型的内部日志,避免重复计数 - 简化 CommandTrendChart 代码,移除不再需要的 _current 逻辑
1 parent 2639f48 commit edf597c

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ async fn build_search_index() -> Result<usize, String> {
10161016
}
10171017

10181018
// Collect command stats from any line containing <command-name>
1019-
if line.contains("<command-name>") {
1019+
// Skip queue-operation entries (internal logs, not actual command invocations)
1020+
if line.contains("<command-name>") && !line.contains("\"type\":\"queue-operation\"") {
10201021
if let Some(ts_str) = &parsed.timestamp {
10211022
if let Ok(ts) = chrono::DateTime::parse_from_rfc3339(ts_str) {
10221023
let week_key = ts.format("%Y-W%V").to_string();
@@ -3775,12 +3776,18 @@ async fn get_command_stats() -> Result<HashMap<String, usize>, String> {
37753776
if file.seek(SeekFrom::Start(prev_size)).is_ok() {
37763777
let mut new_content = String::new();
37773778
if file.read_to_string(&mut new_content).is_ok() {
3778-
for cap in command_pattern.captures_iter(&new_content) {
3779-
if let Some(cmd_name) = cap.get(1) {
3780-
// Remove leading "/" to match cmd.name format
3781-
let name =
3782-
cmd_name.as_str().trim_start_matches('/').to_string();
3783-
*stats.entry(name).or_insert(0) += 1;
3779+
// Process line by line to filter out queue-operation entries
3780+
for line in new_content.lines() {
3781+
if line.contains("\"type\":\"queue-operation\"") {
3782+
continue;
3783+
}
3784+
for cap in command_pattern.captures_iter(line) {
3785+
if let Some(cmd_name) = cap.get(1) {
3786+
// Remove leading "/" to match cmd.name format
3787+
let name =
3788+
cmd_name.as_str().trim_start_matches('/').to_string();
3789+
*stats.entry(name).or_insert(0) += 1;
3790+
}
37843791
}
37853792
}
37863793
}

0 commit comments

Comments
 (0)