【架构优化】从 businessExecutionDuration 中拆出区间并集求和 unionDuration
维护者通常 1 天内回复
评估
调研方向
The logic lives in businessExecutionDuration in internal/repo/analytics_business_delivery.go, at the end of the function where intervals are sorted, merged and summed. Read that function, then extract the merge-and-sum loop into a package-private unionDuration helper. Done means the helper has table-driven tests for empty, disjoint, overlapping, nested, touching and unsorted input, and go test ./internal/repo/ passes. Linked PR #437 already covers this work, so check with maintainers before starting.
由索引模型根据 Issue 内容生成。
描述
现状问题
internal/repo/analytics_business_delivery.go 中 businessExecutionDuration 约 85 行,同时承担三件事:筛选可计入的 run、逐 run 收集并裁剪执行区间、最后对区间排序 → 合并重叠 → 求总时长。末尾的「区间并集求和」是一段与业务无关的纯算法(约 15 行双层循环),内联在长函数里,既不便阅读,也无法单独测试。
重构方案
在同文件内抽出包级纯函数:
// unionDuration 返回区间并集的总时长(重叠/相接的区间只计一次)。
func unionDuration(intervals []domain.RunExecutionInterval) time.Duration
businessExecutionDuration 末尾改为 value := unionDuration(intervals).Milliseconds()。排序、合并条件(!StartedAt.After(FinishedAt),相接也合并)逐字保留。
影响范围
- 仅
internal/repo/analytics_business_delivery.go,包内私有函数,无对外接口变化,无行为变化。 - 不改
domain/run_timing.go中同类逻辑(跨包,不在本次范围)。
验证方式
- 新增
unionDuration表驱动单测:空输入、单区间、不相交、重叠、包含、首尾相接、乱序输入。 - 既有
TestBusinessExecutionDuration*等用例保持通过;go vet ./internal/repo/、go test ./internal/repo/。
- 主要语言
- 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 天内回复