【架构优化】合并 repo/analytics.go 中重复的用户/项目/需求来源累加器取用或新建逻辑
維護者通常 1 天內回覆
評估
研究方向
The duplicated get-or-create logic lives in internal/repo/analytics.go, in accumulateUserUsage, accumulateProjectUsage, accumulateIssueSource and accumulateConversationRun. Read those four functions first to see the shared default values and key formats. The issue names the three helper functions to add, but pull request #474 is already open against this work, so check it before starting. Done means the helpers are used by both callers, the new analytics_accumulator_entry_test.go passes, and go test ./internal/repo/ passes.
由索引模型根據 Issue 內容生成。
描述
现状问题
internal/repo/analytics.go 中「按键取累加器、不存在就新建并写回 map」的代码在两处各写了一遍:
- 责任人 × 自然日:
accumulateUserUsage与accumulateConversationRun(含空责任人归为unassigned、key 拼接) - 项目:
accumulateProjectUsage与accumulateConversationRun(含空项目归为unassigned) - 需求来源:
accumulateIssueSource与accumulateConversationRun
accumulateConversationRun 因此长达约 90 行,且默认值、key 格式、初始字段(如 CostKnown: true、issues map)需要在两处同步维护,容易漂移。
重构方案
新增三个包内函数,两处调用方都改为使用它们:
analyticsUserEntry(values, userID, day)analyticsProjectEntry(values, projectID)analyticsSourceEntry(values, source)(空来源归为local,与accumulateIssueSource原逻辑一致;analyticsIssueSource本身不会返回空串,会话侧行为不变)
只抽取「取或建」部分,累加逻辑保持原样。
影响范围
仅 internal/repo/analytics.go 内部私有函数,不改对外接口、统计口径和返回结果。
验证方式
- 新增
internal/repo/analytics_accumulator_entry_test.go,覆盖默认值、复用同一累加器、不同键新建 gofmt、go vet ./internal/repo/、go test ./internal/repo/(含现有 analytics 全部用例)
- 主要語言
- Go
- 星號
- 141
- 分支
- 28
- 平均合併
- 1 天 15 小時
- 30 天內合併 PR
- 113
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
Tencent/LoopForge 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
[Bug]: 官方镜像未安装 wecom-cli,企业微信通知报「通知服务未安装 wecom-cli」可能已有人在做 @newexploreor 於 1 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
Tencent/LoopForge#156 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
【架构优化】合并 gitwork/workbranch.go 中 push/pull 重复的默认提交身份注入为 withFallbackIdentity可能已有人在做 @fx-kurumi 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 40/100
維護者通常 1 天內回覆
-
【架构优化】从 runtime.installNPMCLI 中拆出 npm 参数拼装 npmCLIInstallArgs 与安装结果启用 activateNPMStage可能已有人在做 @fx-kurumi 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 30/100
維護者通常 1 天內回覆
查看 Tencent/LoopForge 的全部 Issue
相似的 Issue
-
team:library-maintainers
難度 2/5 1-3 小時 新手友好度 82/100
padok-team/burrito#1208 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
bazel-contrib/rules_go#4784 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 62/100
POSIdev-community/aictl#40 ·
-
難度 1/5 1 小時以內 新手友好度 62/100
prime-radiant-inc/evener#6306 ·
維護者通常 1 天內回覆