From f5b0e2c9d2336367dfcf121be6ff5154017192cf Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 29 Aug 2021 15:28:04 +0100 Subject: Simplify split diff view generation and remove JS dependency (#16775) Gitea has relied on some slow JS code to match up added and deleted lines on the diff pages. This can cause a considerable slow down on large diff pages. This PR makes a small change meaning that the matching up can occur much more simply. Partial fix #1351 Signed-off-by: Andrew Thornton --- templates/repo/diff/box.tmpl | 28 ------- templates/repo/diff/section_split.tmpl | 135 ++++++++++++++++++++++----------- 2 files changed, 90 insertions(+), 73 deletions(-) (limited to 'templates') diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 1ca2dcc4d8..4f8f726097 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -154,33 +154,5 @@ {{end}} {{template "repo/issue/view_content/reference_issue_dialog" .}} - - {{if .IsSplitStyle}} - - {{end}} {{end}} diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl index 2f959ac2da..aed6d784b3 100644 --- a/templates/repo/diff/section_split.tmpl +++ b/templates/repo/diff/section_split.tmpl @@ -1,52 +1,97 @@ {{$file := .file}} {{range $j, $section := $file.Sections}} {{range $k, $line := $section.Lines}} - - {{if eq .GetType 4}} - - {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }} - - {{svg "octicon-fold-down"}} - - {{end}} - {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }} - - {{svg "octicon-fold-up"}} - - {{end}} - {{if eq $line.GetExpandDirection 2}} - - {{svg "octicon-fold"}} - - {{end}} - - {{$section.GetComputedInlineDiffFor $line}} - {{else}} - - {{if $line.LeftIdx}}{{end}} - {{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 2))}}{{svg "octicon-plus"}}{{end}}{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} - - {{if $line.RightIdx}}{{end}} - {{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 3))}}{{svg "octicon-plus"}}{{end}}{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} - {{end}} - - {{if gt (len $line.Comments) 0}} - - - - - {{if eq $line.GetCommentSide "previous"}} - {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} - {{end}} - - - - - {{if eq $line.GetCommentSide "proposed"}} - {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} - {{end}} - + {{$hasmatch := ne $line.Match -1}} + {{if or (ne .GetType 2) (not $hasmatch)}} + + {{if eq .GetType 4}} + + {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }} + + {{svg "octicon-fold-down"}} + + {{end}} + {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }} + + {{svg "octicon-fold-up"}} + + {{end}} + {{if eq $line.GetExpandDirection 2}} + + {{svg "octicon-fold"}} + + {{end}} + + {{$section.GetComputedInlineDiffFor $line}} + {{else if and (eq .GetType 3) $hasmatch}}{{/* DEL */}} + {{$match := index $section.Lines $line.Match}} + + + {{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{svg "octicon-plus"}}{{end}}{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} + + {{if $match.RightIdx}}{{end}} + {{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{svg "octicon-plus"}}{{end}}{{if $match.RightIdx}}{{$section.GetComputedInlineDiffFor $match}}{{end}} + {{else}} + + {{if $line.LeftIdx}}{{end}} + {{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 2))}}{{svg "octicon-plus"}}{{end}}{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} + + {{if $line.RightIdx}}{{end}} + {{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 3))}}{{svg "octicon-plus"}}{{end}}{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} + {{end}} + {{if and (eq .GetType 3) $hasmatch}} + {{$match := index $section.Lines $line.Match}} + {{if or (gt (len $line.Comments) 0) (gt (len $match.Comments) 0)}} + + + + + {{if gt (len $line.Comments) 0}} + {{if eq $line.GetCommentSide "previous"}} + {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} + {{end}} + {{end}} + {{if gt (len $match.Comments) 0}} + {{if eq $match.GetCommentSide "previous"}} + {{template "repo/diff/conversation" mergeinto $.root "comments" $match.Comments}} + {{end}} + {{end}} + + + + + {{if eq $line.GetCommentSide "proposed"}} + {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} + {{end}} + {{if gt (len $match.Comments) 0}} + {{if eq $match.GetCommentSide "proposed"}} + {{template "repo/diff/conversation" mergeinto $.root "comments" $match.Comments}} + {{end}} + {{end}} + + + {{end}} + {{else if gt (len $line.Comments) 0}} + + + + + {{if gt (len $line.Comments) 0}} + {{if eq $line.GetCommentSide "previous"}} + {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} + {{end}} + {{end}} + + + + + {{if eq $line.GetCommentSide "proposed"}} + {{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}} + {{end}} + + + {{end}} {{end}} {{end}} {{end}} -- cgit v1.2.3