-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Comments on review should have the same sha #13448
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
Merged
techknowlogick
merged 17 commits into
go-gitea:master
from
zeripath:comments-on-review-should-have-the-same-sha
Nov 9, 2020
Merged
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d1271b1
When replying to an outdated comment it should not appear on the file…
zeripath 4155315
fix test
zeripath d54dfb4
Fix broken migration
zeripath 29c4eb3
Merge branch 'master' into comments-on-review-should-have-the-same-sha
zeripath 43897c0
fix mssql
zeripath 2c776b4
Merge branch 'comments-on-review-should-have-the-same-sha' of github.…
zeripath f438cf5
Merge branch 'master' into comments-on-review-should-have-the-same-sha
techknowlogick 17aa688
Create temporary table because ... well MSSQL ...
zeripath 078c409
Create temporary table because ... well MSSQL ...
zeripath 2e07d05
Create temporary table because ... well MSSQL ...
zeripath aab6e26
fix mssql
zeripath fdc75b4
Merge branch 'master' into comments-on-review-should-have-the-same-sha
techknowlogick c015454
move session within the batch
zeripath 560ee61
regen the sqlcmd each time round the loop
zeripath e6152e6
as per @lunny
zeripath afe1f04
Merge branch 'master' into comments-on-review-should-have-the-same-sha
zeripath 5f38eea
Merge branch 'master' into comments-on-review-should-have-the-same-sha
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func updateCodeCommentReplies(x *xorm.Engine) error { | ||
type Comment struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
CommitSHA string `xorm:"VARCHAR(40)"` | ||
Patch string `xorm:"TEXT patch"` | ||
Invalidated bool | ||
|
||
// Not extracted but used in the below query | ||
Type int `xorm:"INDEX"` | ||
Line int64 // - previous line / + proposed line | ||
TreePath string | ||
ReviewID int64 `xorm:"index"` | ||
} | ||
|
||
if err := x.Sync2(new(Comment)); err != nil { | ||
return err | ||
} | ||
|
||
sess := x.NewSession() | ||
defer sess.Close() | ||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
var start = 0 | ||
var batchSize = 100 | ||
for { | ||
var comments = make([]*Comment, 0, batchSize) | ||
|
||
sqlCmd := `SELECT comment.id as id, first.commit_sha as commit_sha, first.patch as patch, first.invalidated as invalidated | ||
FROM comment INNER JOIN ( | ||
SELECT C.id, C.review_id, C.line, C.tree_path, C.patch, C.commit_sha, C.invalidated | ||
FROM comment AS C | ||
WHERE C.type = 21 | ||
AND C.created_unix = | ||
(SELECT MIN(comment.created_unix) | ||
FROM comment | ||
WHERE comment.review_id = C.review_id | ||
AND comment.type = 21 | ||
AND comment.line = C.line | ||
AND comment.tree_path = C.tree_path) | ||
) AS first | ||
ON comment.review_id = first.review_id | ||
AND comment.tree_path = first.tree_path AND comment.line = first.line | ||
WHERE comment.type = 21 | ||
AND comment.id != first.id | ||
AND comment.commit_sha != first.commit_sha` | ||
|
||
switch { | ||
case setting.Database.UseMySQL: | ||
sqlCmd += " LIMIT " + strconv.Itoa(batchSize) + ", " + strconv.Itoa(start) | ||
case setting.Database.UsePostgreSQL: | ||
fallthrough | ||
case setting.Database.UseSQLite3: | ||
sqlCmd += " LIMIT " + strconv.Itoa(batchSize) + " OFFSET " + strconv.Itoa(start) | ||
case setting.Database.UseMSSQL: | ||
sqlCmd = "SELECT TOP " + strconv.Itoa(batchSize) + sqlCmd[6:] + | ||
" AND (id NOT IN ( SELECT TOP " + strconv.Itoa(start) + sqlCmd[6:] + "))" | ||
default: | ||
return fmt.Errorf("Unsupported database type") | ||
} | ||
|
||
if err := sess.SQL(sqlCmd).Find(&comments); err != nil { | ||
log.Error("failed to select: %v", err) | ||
return err | ||
} | ||
|
||
for _, comment := range comments { | ||
if _, err := sess.Table("comment").ID(comment.ID).Cols("commit_sha", "patch", "invalidated").Update(comment); err != nil { | ||
log.Error("failed to update comment[%d]: %v %v", comment.ID, comment, err) | ||
return err | ||
} | ||
} | ||
|
||
start += len(comments) | ||
|
||
if len(comments) < batchSize { | ||
break | ||
} | ||
} | ||
|
||
return sess.Commit() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.