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 cacher for gorm to reduce the load of db #3734

Merged
merged 1 commit into from
Dec 30, 2024
Merged

Conversation

gaius-qi
Copy link
Member

Description

This pull request includes several changes to the go.mod file and the manager/database package to add caching functionality using GORM and LRU. The most important changes include adding new dependencies, implementing a cache mechanism, and integrating the cache with the database.

Dependencies Update:

  • Added github.com/go-gorm/caches/v4 v4.0.5 to the go.mod file.
  • Added github.com/hashicorp/golang-lru/v2 v2.0.7 to the go.mod file.
  • Updated gorm.io/gorm from v1.24.6 to v1.25.0 in the go.mod file.

Cache Implementation:

  • Implemented a new cacher struct in manager/database/cacher.go to use LRU for GORM caching.
  • Added a new newCacher function to create a cacher instance and methods to Get, Store, and Invalidate cache entries.

Cache Integration:

  • Imported github.com/go-gorm/caches/v4 in manager/database/database.go.
  • Modified the New function in manager/database/database.go to initialize and use the new cache mechanism, reducing database load.

Related Issue

Motivation and Context

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update (if none of the other choices apply)

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@gaius-qi gaius-qi added the enhancement New feature or request label Dec 30, 2024
@gaius-qi gaius-qi added this to the v2.2.0 milestone Dec 30, 2024
@gaius-qi gaius-qi self-assigned this Dec 30, 2024
@gaius-qi gaius-qi requested a review from a team as a code owner December 30, 2024 08:25
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.

Project coverage is 35.13%. Comparing base (4d7bdc5) to head (7dba77f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
manager/database/cacher.go 0.00% 33 Missing ⚠️
manager/database/database.go 0.00% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3734      +/-   ##
==========================================
- Coverage   35.16%   35.13%   -0.03%     
==========================================
  Files         335      336       +1     
  Lines       37807    37852      +45     
==========================================
+ Hits        13295    13301       +6     
- Misses      23680    23722      +42     
+ Partials      832      829       -3     
Flag Coverage Δ
unittests 35.13% <0.00%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
manager/database/database.go 0.00% <0.00%> (ø)
manager/database/cacher.go 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

@gaius-qi gaius-qi force-pushed the feature/cacher branch 3 times, most recently from 38dd2d5 to 0a71db1 Compare December 30, 2024 09:01
Signed-off-by: Gaius <gaius.qi@gmail.com>
Copy link
Member

@chlins chlins left a comment

Choose a reason for hiding this comment

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

lgtm

@gaius-qi gaius-qi merged commit 14cf937 into main Dec 30, 2024
24 checks passed
@gaius-qi gaius-qi deleted the feature/cacher branch December 30, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants