-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Next round of db.DefaultContext
refactor
#27089
Conversation
func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error { | ||
ctx, committer, err := db.TxContext(db.DefaultContext) | ||
func RemoveLabel(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error { | ||
dbCtx, committer, err := db.TxContext(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I summon @wxiaoguang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "notification" framework has some legacy design problems.
I guess maybe the code could be like this (and the same for ReplaceLabels or others) to avoid the ctx
trick.
err := db.WithTx(ctx, func (...) {
...
})
if err == nil {
notify_service.......
}
return err
@@ -68,7 +68,7 @@ func (u *User) WebAuthnIcon() string { | |||
|
|||
// WebAuthnCredentials implementns the webauthn.User interface | |||
func (u *User) WebAuthnCredentials() []webauthn.Credential { | |||
dbCreds, err := auth.GetWebAuthnCredentialsByUID(u.ID) | |||
dbCreds, err := auth.GetWebAuthnCredentialsByUID(db.DefaultContext, u.ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pity that we can't fix that at the moment as it is used in the templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have ctx
in templates (#26254).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but not yet for any usecase, correct?
Or can it simply be used in every template even those that don't have it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's safe to use ctx
in any template. I was going to refactor more, but there is an open PR #26745 which would conflict with the ctx
refactoring. I do not want to introduce too many conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find a template that is using this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean GetWebAuthnCredentialsByUID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I think it's safe to remove func WebAuthnCredentials
(While as a refactoring PR, search&replace is good enough, I don't consider the removal is a must, the removal could be done later)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a refactoring PR, it looks good to me. No block from my side. Some nits (like dbCtx) could be left to the future. Actually there are some other dbCtx
usages in code, they could be refactored together.
* giteaoffical/main: (23 commits) Search branches (go-gitea#27055) Fix wrong migration for email address (go-gitea#27106) [skip ci] Updated translations via Crowdin Support `.git-blame-ignore-revs` file (go-gitea#26395) Add `RemoteAddress` to mirrors (go-gitea#26952) Upgrading the actions/checkout@4 (go-gitea#27096) Next round of `db.DefaultContext` refactor (go-gitea#27089) Ui correction in mobile view nav bar left aligned items. (go-gitea#27046) Add missing deps to files-changed (go-gitea#27100) Use db.WithTx for AddTeamMember to avoid ctx abuse (go-gitea#27095) Drop Node.js 16 and update js dependencies (go-gitea#27094) Fix NPE when editing OAuth2 applications (go-gitea#27078) Use `print` instead of `printf` (go-gitea#27093) Add tests for db indexer in indexer_test.go (go-gitea#27087) [skip ci] Updated translations via Crowdin Allow empty Conan files (go-gitea#27092) Actions are no longer experimental, so enable them by default (go-gitea#27054) Update brew installation documentation since gitea moved to brew core package (go-gitea#27070) More refactoring of `db.DefaultContext` (go-gitea#27083) [skip ci] Updated translations via Crowdin ...
* origin/main: (53 commits) Search branches (go-gitea#27055) Fix wrong migration for email address (go-gitea#27106) [skip ci] Updated translations via Crowdin Support `.git-blame-ignore-revs` file (go-gitea#26395) Add `RemoteAddress` to mirrors (go-gitea#26952) Upgrading the actions/checkout@4 (go-gitea#27096) Next round of `db.DefaultContext` refactor (go-gitea#27089) Ui correction in mobile view nav bar left aligned items. (go-gitea#27046) Add missing deps to files-changed (go-gitea#27100) Use db.WithTx for AddTeamMember to avoid ctx abuse (go-gitea#27095) Drop Node.js 16 and update js dependencies (go-gitea#27094) Fix NPE when editing OAuth2 applications (go-gitea#27078) Use `print` instead of `printf` (go-gitea#27093) Add tests for db indexer in indexer_test.go (go-gitea#27087) [skip ci] Updated translations via Crowdin Allow empty Conan files (go-gitea#27092) Actions are no longer experimental, so enable them by default (go-gitea#27054) Update brew installation documentation since gitea moved to brew core package (go-gitea#27070) More refactoring of `db.DefaultContext` (go-gitea#27083) [skip ci] Updated translations via Crowdin ...
Part of #27065