Skip to content

feat(version): add version history list#476

Open
155TuT wants to merge 17 commits into
west2-online:mainfrom
155TuT:feat/version-history
Open

feat(version): add version history list#476
155TuT wants to merge 17 commits into
west2-online:mainfrom
155TuT:feat/version-history

Conversation

@155TuT

@155TuT 155TuT commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

第一个提交(6ad6de8)

  • 在redis中新增version_history表,支持GORM软删除以进行审计轨迹
  • GetVersionHistoryList RPC 会返回按created_at描述排序的所有版本记录
  • UploadVersion 现在会将每个上传的版本(发布/测试版)存续到version_history
  • 新的二手结构体:VersionHistory,GetVersionHistoryList{请求,响应}
  • 修复 UploadVersion UPYUN 上传路径中的错误信息

第二个提交(a1aa076)

GetReleaseVersion/GetBetaVersion 现在从 version_history DB 读取 10 分钟 Redis 缓存

具体改动:

  • internal/version/service/get_version.go的line 28-52 -- Cache-Aside 模式:先查 Redis,miss 则查 DB 再回填缓存
  • pkg/cache/version/latest_version.go -- GetLatestVersionCache / SetLatestVersionCache / DeleteLatestVersionCache
  • pkg/db/version/get_version_history.go的line 36-48 -- GetLatestVersionByType 含 ErrRecordNotFound 处理
  • pkg/constants/redis.go的line 47,43 -- LatestVersionCachePrefix + LatestVersionKeyExpire(10min)
  • Internal/Version/Service/upload_version.go的line 76 -- 上传后同步更新缓存
  • pkg/db/version/add_version_history.go的line 36-48 -- 已拆到 pkg/db/version/get_version_history.go,包括 GetVersionHistoryList 和 GetLatestVersionByType ,原文件只保留了 CreateversionHistory
  • idl/version.thrift的line 144-153 -- 已移到model.thrift中并删除了原文件中的 VersionHistory

自查 PR 结构

  • PR 标题符合这个格式: <type>(optional scope): <description>

  • 此 PR 标题的描述以用户为导向,足够清晰,其他人可以理解。

  • 我已经对所有 commit 提供了签名(GPG 密钥签名、SSH 密钥签名)

  • 这个 PR 属于强制变更/破坏性更改

如果是,请在 PR 标题中添加 BREAKING CHANGE 前缀,并在 PR 描述中详细说明。

这个 PR 的类型是什么?

feat

这个 PR 做了什么 / 我们为什么需要这个 PR?

新增版本历史列表接口,用于:“发版了以后撤回一类的,还有就是对接一下我们后面的对API请求头版本信息相关的统计,方便看一下什么时间发的版本还在有人用,算是一个比较小的需求” ----baoshuo

(可选)这个 PR 解决了哪个/些 issue?

用以解决issues 446,新增版本历史列表接口,开一个pr先给大家审查,确保理解的标准和规范无误再增加其他接口

对 Reviewer 预留的一些提醒

已使用 SKILL.md 自查、通过本地编译,但未进行服务器部署测试(还不熟悉 + 没权限操作服务器)

155TuT and others added 3 commits April 27, 2026 21:48
…t endpoint

- New version_history table with GORM soft-delete for audit trail
- GetVersionHistoryList RPC returns all version records ordered by created_at desc
- UploadVersion now persists each uploaded version (release/beta) to version_history
- New Thrift structs: VersionHistory, GetVersionHistoryList{Request,Response}
- Fix incorrect error messages in UploadVersion UPYUN upload paths
…ersionHistory to model

- Move VersionHistory struct from version.thrift to model.thrift (PR review)
- Split GetVersionHistoryList into separate DB file (PR review)
- Rewrite GetReleaseVersion/GetBetaVersion to read from DB with Redis cache instead of UPYUN
- Add GetLatestVersionByType DB query with ErrRecordNotFound handling
- Add Redis cache (get/set/delete) for latest version per type
- Update UploadVersion to refresh cache after DB write
- Add boundary tests: empty list, cache hit/miss, DB error, no record
@155TuT 155TuT requested review from a team, jiuxia211, mutezebra and ozline as code owners April 27, 2026 14:49
@155TuT 155TuT force-pushed the feat/version-history branch from ee51ad7 to 08593b1 Compare April 29, 2026 12:22
@155TuT

155TuT commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

变基并重新推送以补充SSH签名。对不起我不知道为什么昨天提交的又没有签名

@renbaoshuo renbaoshuo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

版本历史接口需要管理身份的鉴权,普通用户不能看

Comment thread internal/version/service/get_version.go Outdated
return nil, fmt.Errorf("getLatestVersion: no %s version found in database", versionType)
}
// Populate cache (ignore cache write errors — non-critical path)
_ = s.cache.Version.SetLatestVersionCache(s.ctx, vh)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该丢 taskqueue 异步写缓存吧

Comment thread config/sql/init.sql Outdated
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `idx_created_at` (`created_at`),
INDEX `idx_type` (`type`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再加一下实际请求时候排序等需要的索引

Comment on lines +76 to +79
// Refresh the latest version cache for this type so GetReleaseVersion/GetBetaVersion
// return the newly uploaded version immediately. Cache write failure is non-critical.
_ = s.cache.Version.SetLatestVersionCache(s.ctx, vh)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方应该是删掉旧缓存,不然你的请求永远不会打到数据库里面其实

Comment thread pkg/constants/redis.go Outdated
PaperFileDirKeyExpire = 2 * ONE_DAY // [paper] 历年卷文件目录
AcademicScoresExpire = 5 * ONE_MINUTE // [academic] 成绩信息
VisitExpire = 1 * ONE_DAY // [version]访问统计
LatestVersionKeyExpire = 10 * ONE_MINUTE // [version]最新版本缓存

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以长点

Comment thread pkg/db/version/create_version_history.go
@renbaoshuo

Copy link
Copy Markdown
Member

对了,加个分页

@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.92754% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/version/service/get_version.go 85.00% 2 Missing and 1 partial ⚠️
internal/version/service/service.go 80.00% 1 Missing and 1 partial ⚠️
internal/version/service/upload_version.go 84.61% 1 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##             main     #476      +/-   ##
==========================================
- Coverage   63.81%   63.46%   -0.35%     
==========================================
  Files         230      234       +4     
  Lines        6027     6142     +115     
==========================================
+ Hits         3846     3898      +52     
- Misses       2057     2120      +63     
  Partials      124      124              
Flag Coverage Δ
unittest 63.46% <94.92%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/handler/api/version_service.go 96.73% <100.00%> (+0.33%) ⬆️
internal/version/service/get_version_history.go 100.00% <100.00%> (ø)
pkg/cache/version/latest_version.go 100.00% <100.00%> (ø)
pkg/db/version/create_version_history.go 100.00% <100.00%> (ø)
pkg/db/version/get_version_history.go 100.00% <100.00%> (ø)
internal/version/service/service.go 84.61% <80.00%> (-15.39%) ⬇️
internal/version/service/upload_version.go 94.11% <84.61%> (-5.89%) ⬇️
internal/version/service/get_version.go 86.95% <85.00%> (-13.05%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +34 to +44
type getVersionHistoryListRequest struct {
Password string `form:"password,required" query:"password,required" json:"password,required"`
Limit *int64 `form:"limit" query:"limit" json:"limit,omitempty"`
PageToken *int64 `form:"page_token" query:"page_token" json:"page_token,omitempty"`
}

type getVersionHistoryListResponse struct {
Data any `json:"data"`
PageToken *int64 `json:"page_token,omitempty"`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个为啥加到这里?不对吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants