【架构优化】合并 repo/analytics.go 中重复的用户/项目/需求来源累加器取用或新建逻辑

Aperta
#473 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@fx-kurumi ci sta già lavorando.

Dal 13/11/2026.

  • #474 di @fx-kurumi — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

现状问题

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 全部用例)
Lingua principale
Go
Stelle
141
Fork
28
Merge medio
1g 15h
PR unite (30g)
113

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Tencent/LoopForge

Tutte le issue di Tencent/LoopForge

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.