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

DBContext is just a Context #17100

Merged
merged 8 commits into from
Sep 23, 2021
Merged

Conversation

zeripath
Copy link
Contributor

This PR removes some of the specialness from the DBContext and makes it context
This allows us to simplify the GetEngine code to wrap around any context in future
and means that we can change our loadRepo(e Engine) functions to simply take contexts.

Signed-off-by: Andrew Thornton [email protected]

This PR removes some of the specialness from the DBContext and makes it context
This allows us to simplify the GetEngine code to wrap around any context in future
and means that we can change our loadRepo(e Engine) functions to simply take contexts.

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath zeripath added the type/enhancement An improvement of existing functionality label Sep 20, 2021
@zeripath zeripath added this to the 1.16.0 milestone Sep 20, 2021
@zeripath zeripath added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Sep 20, 2021
@lafriks
Copy link
Member

lafriks commented Sep 20, 2021

unit tests fail

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 20, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #17100 (6b87fc2) into main (f2e7d54) will increase coverage by 0.00%.
The diff coverage is 62.42%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17100   +/-   ##
=======================================
  Coverage   45.31%   45.31%           
=======================================
  Files         773      773           
  Lines       86873    86907   +34     
=======================================
+ Hits        39366    39382   +16     
- Misses      41151    41163   +12     
- Partials     6356     6362    +6     
Impacted Files Coverage Δ
models/action.go 48.86% <0.00%> (ø)
models/avatar.go 35.38% <0.00%> (ø)
models/fixture_generation.go 70.00% <0.00%> (ø)
models/gpg_key_verify.go 13.46% <0.00%> (ø)
models/issue_lock.go 0.00% <0.00%> (ø)
models/list_options.go 77.14% <0.00%> (ø)
models/migrate.go 0.00% <0.00%> (ø)
models/oauth2.go 27.27% <0.00%> (ø)
models/repo_archiver.go 6.25% <0.00%> (ø)
models/repo_generate.go 15.00% <0.00%> (ø)
... and 116 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2e7d54...6b87fc2. Read the comment docs.

models/attachment.go Outdated Show resolved Hide resolved
Comment on lines +26 to +31
stats.Counter.PublicKey, _ = db.GetEngine(db.DefaultContext).Count(new(PublicKey))
stats.Counter.Repo = CountRepositories(true)
stats.Counter.Watch, _ = db.DefaultContext().Engine().Count(new(Watch))
stats.Counter.Star, _ = db.DefaultContext().Engine().Count(new(Star))
stats.Counter.Action, _ = db.DefaultContext().Engine().Count(new(Action))
stats.Counter.Access, _ = db.DefaultContext().Engine().Count(new(Access))
stats.Counter.Watch, _ = db.GetEngine(db.DefaultContext).Count(new(Watch))
stats.Counter.Star, _ = db.GetEngine(db.DefaultContext).Count(new(Star))
stats.Counter.Action, _ = db.GetEngine(db.DefaultContext).Count(new(Action))
stats.Counter.Access, _ = db.GetEngine(db.DefaultContext).Count(new(Access))
Copy link
Member

Choose a reason for hiding this comment

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

Could introduce a variable to reduce the calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you might imagine, the code was a result of a mass find and replace.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but could be changed while working at it.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Sep 22, 2021
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 23, 2021
@lunny
Copy link
Member

lunny commented Sep 23, 2021

Please resolve the conflicts.

@zeripath
Copy link
Contributor Author

make lgtm work

@lunny lunny merged commit 9302eba into go-gitea:main Sep 23, 2021
@zeripath zeripath deleted the db-context-is-a-context branch September 23, 2021 16:10
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants