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

Penultimate round of db.DefaultContext refactor #27414

Merged
merged 9 commits into from
Oct 11, 2023

Conversation

JakobDev
Copy link
Contributor

@JakobDev JakobDev commented Oct 3, 2023

Part of #27065

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 3, 2023
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 3, 2023
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 3, 2023
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 3, 2023
@delvh delvh added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Oct 3, 2023
Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

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

Other instances I've found:
ComposeMetas:

user/dashboard/feeds.tmpl
93:                                                                     {{RenderCommitMessage $.Context .Message $repoLink $.ComposeMetas}}

repo/commit_page.tmpl
22:                             <h3 class="gt-mb-0 gt-f1"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}</h3>
138:                            <pre class="commit-body">{{RenderCommitBody $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</pre>
279:                            <pre class="commit-body">{{RenderNote $.Context .Note $.RepoLink $.Repository.ComposeMetas}}</pre>

repo/branch/list.tmpl
28:                                                             <p class="info gt-df gt-ac gt-my-2">{{svg "octicon-git-commit" 16 "gt-mr-2"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage .RepoLink .Repository.ComposeMetas}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DefaultBranchBranch.DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p>
104:                                                                    <p class="info gt-df gt-ac gt-my-2">{{svg "octicon-git-commit" 16 "gt-mr-2"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .DBBranch.CommitID}}">{{ShortSha .DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DBBranch.CommitMessage $.RepoLink $.Repository.ComposeMetas}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} &nbsp;{{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}</p>

repo/commits_list_small.tmpl
41:             <span class="gt-mono commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}</span>
46:                     <pre class="commit-body gt-hidden">{{RenderCommitBody $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}</pre>

repo/graph/commits.tmpl
32:                                             <span>{{RenderCommitMessage $.Context $commit.Subject $.RepoLink $.Repository.ComposeMetas}}</span>

repo/commits_list.tmpl
63:                                                             <span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.Context .Message $commitRepoLink $commitLink $.Repository.ComposeMetas}}</span>
71:                                                     <pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink $.Repository.ComposeMetas}}</pre>

repo/diff/compare.tmpl
197:                                            <span id="issue-title">{{RenderIssueTitle $.Context .PullRequest.Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>

AllowsPulls:

repo/branch/list.tmpl
128:                                                                            {{else if and (not .DBBranch.IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}}
134:                                                                            {{if and (not .DBBranch.IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}}

models/auth/source.go Show resolved Hide resolved
models/issues/issue_project.go Outdated Show resolved Hide resolved
templates/shared/issueicon.tmpl Outdated Show resolved Hide resolved
templates/repo/view_list.tmpl Outdated Show resolved Hide resolved
@6543 6543 added this to the 1.22.0 milestone Oct 3, 2023
@lunny lunny removed modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Oct 6, 2023
@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 Oct 8, 2023
@delvh
Copy link
Member

delvh commented Oct 8, 2023

Ping for other reviewers

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

I do not feel safe to change the template-related code too much (there are many regressions).

In most (all) cases, the methods used by templates don't need to strictly follow the database context because they can't be in a transaction.

To (partially) resolve the "template code is dynamic" problem, using unique and longer names is the only choice. That's why I keep calling out to use at least 2 words for method/variable names. Then many .Link regressions could be avoided. And the changed functions should be searched in all templates when refactoring.

And to make the release progress safe, the refactoring time is also important. It's better to do it when the last release is stable enough, and avoid backporting large refactoring. Then people would have enough time to eat the dogfood.


Since the refactoring has started, it shouldn't stop halfway, so I vote my approval here. Hopefully the regressions could be fixed ASAP.

@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 Oct 9, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Oct 10, 2023
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Oct 10, 2023
@lunny lunny enabled auto-merge (squash) October 10, 2023 13:36
@lunny lunny disabled auto-merge October 11, 2023 03:40
@lunny lunny enabled auto-merge (squash) October 11, 2023 03:43
@lunny lunny merged commit ebe803e into go-gitea:main Oct 11, 2023
25 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Oct 11, 2023
@JakobDev JakobDev deleted the nodefaultctx branch October 11, 2023 06:04
@silverwind
Copy link
Member

silverwind commented Oct 11, 2023

Dashboard does not render any more for me. Is it related?

Render failed, failed to render template: user/dashboard/dashboard, error: template error: builtin(static):user/dashboard/feeds:93:62 : executing "user/dashboard/feeds" at <$.ComposeMetas>: ComposeMetas is not a method but has arguments
----------------------------------------------------------------------
									{{RenderCommitMessage $.Context .Message $repoLink ($.ComposeMetas ctx)}}

If this is a valid issue, I really wonder how that could have slipped through.

@lunny lunny mentioned this pull request Oct 11, 2023
@JakobDev
Copy link
Contributor Author

Is it related?

It is related. This variable has the same name as a function I changed.

I do not feel safe to change the template-related code too much

I'm also not sure about it, but the current refactoring don't land in 1.21, so we have enough time to find problems.

In most (all) cases, the methods used by templates don't need to strictly follow the database context because they can't be in a transaction.

I recently had a database deadlock, because one function called in a transaction was using db.DefaultContext. This function was not used by a template, but there is always a risk, so I think it's better to take the pill and change it during the refactoring.

Luckily the next round will likely be the last.

@silverwind
Copy link
Member

We need at least some test coverage for typical pages which have been recently regressed with these refactors, like frontpage, pull request view etc. Should be complex scenarios with all the states in them etc.

silverwind pushed a commit that referenced this pull request Oct 11, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Oct 12, 2023
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Keep filter when showing unfiltered results on explore page (go-gitea#27192)
  Don't show Link to TOTP if not set up (go-gitea#27585)
  Fix data-race bug when accessing task.LastRun (go-gitea#27584)
  Fix template bug (go-gitea#27581)
  Replace ajax with fetch, improve image diff (go-gitea#27267)
  Replace assert.Fail with assert.FailNow (go-gitea#27578)
  Fix the robots.txt path
  show manual cron run's last time (go-gitea#27544)
  fully replace drone with actions (go-gitea#27556)
  Revert "Simplify `contrib/backport` (go-gitea#27520)" (go-gitea#27566)
  Align ISSUE_TEMPLATE with the new label system (go-gitea#27573)
  Penultimate round of `db.DefaultContext` refactor (go-gitea#27414)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jan 9, 2024
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. modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. 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.

None yet

7 participants