Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cache and optimize logic in user.GetInfo and term.TermList #170

Merged
merged 17 commits into from
Feb 12, 2025

Conversation

FantasyRL
Copy link
Member

@FantasyRL FantasyRL commented Feb 1, 2025

自查 PR 结构

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

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

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

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

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

这个 PR 的类型是什么?

feat && fix

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

  • 对user_info接口进行了逻辑的修正并增加了缓存
    image
  • 为获取学期列表添加了缓存
    image
  • 为获取就读学期列表添加了缓存
    image
  • 为获取课程列表添加了缓存
    image

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

stuInfo(#149)

对 Reviewer 预留的一些提醒

@ozline
Copy link
Member

ozline commented Feb 1, 2025

怎么感觉怪怪的,你开 commit 签名了吗

@FantasyRL
Copy link
Member Author

怎么感觉怪怪的,你开 commit 签名了吗

昨天token过期了

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 31.38686% with 94 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/cache/common/get_term_list.go 0.00% 10 Missing ⚠️
pkg/cache/course/get_terms.go 0.00% 10 Missing ⚠️
pkg/cache/user/get_user_info.go 0.00% 10 Missing ⚠️
pkg/cache/common/set_term_list.go 0.00% 9 Missing ⚠️
pkg/cache/course/set_terms.go 0.00% 9 Missing ⚠️
pkg/cache/user/set_user_info.go 0.00% 9 Missing ⚠️
internal/user/service/get_info.go 72.00% 4 Missing and 3 partials ⚠️
pkg/db/user/create_student.go 0.00% 6 Missing ⚠️
pkg/cache/common/common.go 0.00% 4 Missing ⚠️
pkg/cache/course/course.go 0.00% 4 Missing ⚠️
... and 7 more
@@           Coverage Diff            @@
##            main    #170      +/-   ##
========================================
+ Coverage   3.21%   3.31%   +0.09%     
========================================
  Files        200     209       +9     
  Lines      41224   41359     +135     
========================================
+ Hits        1327    1371      +44     
- Misses     39818   39905      +87     
- Partials      79      83       +4     
Flag Coverage Δ
unittest 3.31% <31.38%> (+0.09%) ⬆️

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

Files with missing lines Coverage Δ
internal/common/service/service.go 100.00% <100.00%> (ø)
internal/course/service/service.go 100.00% <100.00%> (ø)
internal/user/service/service.go 100.00% <100.00%> (ø)
cmd/common/main.go 0.00% <0.00%> (ø)
cmd/course/main.go 0.00% <0.00%> (ø)
cmd/user/main.go 0.00% <0.00%> (ø)
internal/common/service/term.go 86.95% <72.72%> (-13.05%) ⬇️
internal/course/service/get_terms.go 64.00% <75.00%> (+4.00%) ⬆️
pkg/cache/cache.go 0.00% <0.00%> (ø)
pkg/cache/common/common.go 0.00% <0.00%> (ø)
... and 10 more

... and 8 files with indirect coverage changes

@FantasyRL FantasyRL marked this pull request as ready for review February 2, 2025 08:55
@ozline
Copy link
Member

ozline commented Feb 5, 2025

图里面几个过期时间设置的时间写在 pr 里哈

@FantasyRL FantasyRL changed the title feat: add cache and optimize logic in user.GetInfo feat: add cache and optimize logic in user.GetInfo and term.TermList Feb 5, 2025
@FantasyRL FantasyRL requested a review from a team as a code owner February 6, 2025 03:47
@jiuxia211
Copy link
Contributor

这个pr可以合了吗

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 26 changed files in this pull request and generated no comments.

Files not reviewed (15)
  • cmd/common/main.go: Evaluated as low risk
  • pkg/cache/course/course.go: Evaluated as low risk
  • pkg/cache/common/set_term_list.go: Evaluated as low risk
  • pkg/cache/common/common.go: Evaluated as low risk
  • pkg/cache/cache.go: Evaluated as low risk
  • internal/user/service/service.go: Evaluated as low risk
  • internal/common/service/service.go: Evaluated as low risk
  • internal/course/service/service.go: Evaluated as low risk
  • cmd/user/main.go: Evaluated as low risk
  • cmd/course/main.go: Evaluated as low risk
  • internal/user/service/get_info_test.go: Evaluated as low risk
  • internal/course/service/get_terms.go: Evaluated as low risk
  • internal/course/service/get_terms_test.go: Evaluated as low risk
  • internal/common/service/term.go: Evaluated as low risk
  • internal/user/service/get_info.go: Evaluated as low risk
"github.com/west2-online/jwch"
)

func (s *CommonService) GetTermList() (*jwch.SchoolCalendar, error) {
exist := s.cache.IsKeyExist(s.ctx, constants.TermListKey)
Copy link
Member

Choose a reason for hiding this comment

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

这个改成 if s.cache.IsKeyExist(s.ctx, constants.TermListKey) {}就可以

@@ -37,12 +37,23 @@ func (s *CourseService) GetTermsList(req *course.TermListRequest) ([]string, err
return nil, fmt.Errorf("service.GetTermList: Get login data fail: %w", err)
}

stu := jwch.NewStudent().WithLoginData(loginData.GetId(), utils.ParseCookies(loginData.GetCookies()))
e := s.cache.IsKeyExist(s.ctx, loginData.GetId())
Copy link
Member

Choose a reason for hiding this comment

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

同上

// 查询数据库是否存入此学生信息
// 查询cache
existCache := s.cache.IsKeyExist(s.ctx, stuId)
if existCache {
Copy link
Member

Choose a reason for hiding this comment

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

同上

exist, stuInfo, err := s.db.User.GetStudentById(s.ctx, stuId)
IsUpdate := false
if err != nil {
return nil, fmt.Errorf("service.GetUserInfo: %w", err)
}
if exist {
Copy link
Member

Choose a reason for hiding this comment

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

这个不用删掉 exist,因为逻辑比前面那个复杂

@ozline ozline merged commit 4a6532e into west2-online:main Feb 12, 2025
5 of 6 checks passed
@FantasyRL FantasyRL deleted the not_main branch February 12, 2025 11:15
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.

3 participants