* 更新指令使用统计(独立于历史记录,用于匹配推荐排序)
(options: {
path: string
type?: 'app' | 'plugin'
featureCode?: string
name?: string
})
| 771 | * 更新指令使用统计(独立于历史记录,用于匹配推荐排序) |
| 772 | */ |
| 773 | private updateUsageStats(options: { |
| 774 | path: string |
| 775 | type?: 'app' | 'plugin' |
| 776 | featureCode?: string |
| 777 | name?: string |
| 778 | }): void { |
| 779 | try { |
| 780 | const { path: cmdPath, type = 'app', featureCode, name: cmdName } = options |
| 781 | |
| 782 | console.log('[Commands] 更新指令使用统计:', cmdName || cmdPath) |
| 783 | |
| 784 | const now = Date.now() |
| 785 | |
| 786 | // 读取使用统计 |
| 787 | const stats: any[] = databaseAPI.dbGet('command-usage-stats') || [] |
| 788 | |
| 789 | // 查找是否已存在(非插件类型需要同时匹配 name 和 path,支持同路径不同名应用) |
| 790 | const existingIndex = findCommandIndex(stats, cmdPath, type, featureCode, cmdName || cmdPath) |
| 791 | |
| 792 | if (existingIndex >= 0) { |
| 793 | // 已存在,更新使用时间和次数 |
| 794 | stats[existingIndex].lastUsed = now |
| 795 | stats[existingIndex].useCount = (stats[existingIndex].useCount || 0) + 1 |
| 796 | console.log(`更新统计: ${cmdName || cmdPath}, 使用${stats[existingIndex].useCount}次`) |
| 797 | } else { |
| 798 | // 新记录 |
| 799 | stats.push({ |
| 800 | path: cmdPath, |
| 801 | type, |
| 802 | featureCode: featureCode || null, |
| 803 | name: cmdName || cmdPath, |
| 804 | lastUsed: now, |
| 805 | useCount: 1 |
| 806 | }) |
| 807 | console.log(`新增统计: ${cmdName || cmdPath}, 使用1次`) |
| 808 | } |
| 809 | |
| 810 | // 保存统计数据 |
| 811 | databaseAPI.dbPut('command-usage-stats', stats) |
| 812 | |
| 813 | console.log('[Commands] 使用统计已更新') |
| 814 | } catch (error) { |
| 815 | console.error('[Commands] 更新使用统计失败:', error) |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * 从数据库获取插件列表 |
no test coverage detected