-
-
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
Fix "Dashboard shows deleted comments" #1995
Conversation
Signed-off-by: Jonas <info@jonasfranz.software>
Added explanation to return statement. Signed-off-by: Jonas <info@jonasfranz.software>
Added explanation to return statement + documentation. Signed-off-by: Jonas <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
…pants. Signed-off-by: Jonas Franz <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Refreshing code base
Deleting feed entry if a comment is going to be deleted Signed-off-by: Jonas Franz <info@jonasfranz.software>
Signed-off-by: Jonas Franz <email@jfdev.de>
Added improved links to comments in feed entries. Signed-off-by: Jonas Franz <email@jfdev.de>
Added improved links to comments in feed entries. Signed-off-by: Jonas Franz <email@jfdev.de>
Added improved links to comments in feed entries. Signed-off-by: Jonas Franz <email@jfdev.de>
Added improved links to comments in feed entries. (+ gofmt) Signed-off-by: Jonas Franz <email@jfdev.de>
Added improved links to comments in feed entries. (+ gofmt) Signed-off-by: Jonas Franz <email@jfdev.de>
models/action.go
Outdated
@@ -22,6 +22,7 @@ import ( | |||
"code.gitea.io/gitea/modules/base" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/setting" | |||
"strconv" |
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.
standard lib should be at the first
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.
- Done
Added improved links to comments in feed entries. (+ gofmt) Signed-off-by: Jonas Franz <email@jfdev.de>
models/migrations/v35.go
Outdated
@@ -0,0 +1,24 @@ | |||
// Copyright 2017 The Gogs Authors. All rights reserved. |
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.
Gitea authors
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.
- Done
Added improved links to comments in feed entries. (+ gofmt) Signed-off-by: Jonas Franz <email@jfdev.de>
routers/user/home.go
Outdated
comment, err = models.GetCommentByID(act.CommentID) | ||
if err != nil { | ||
if models.IsErrCommentNotExist(err) { | ||
continue |
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.
This continue
will prevent the action's repo owner from being loaded.
templates/user/dashboard/feeds.tmpl
Outdated
<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p> | ||
{{else if eq .GetOpType 11}} | ||
<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p> | ||
{{else if (or (or (eq .GetOpType 12) (eq .GetOpType 13)) (or (eq .GetOpType 14) (eq .GetOpType 15)))}} | ||
<span class="text truncate issue title has-emoji">{{.GetIssueTitle}}</span> | ||
<a href="{{.GetCommentLink}}" class="text truncate issue title has-emoji">{{.GetIssueTitle}}</a> |
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 dislike using .GetCommentLink
for actions that don't have anything to do with comments. I know that .GetCommentLink
will return the link to the issue in this case, but it seems sloppy.
IMO, the best solution here is to add IssueID
and Issue
fields to the Action
struct. This would allow us to just use .Issue.HTMLURL
here, and .Comment.HTMLURL
in line 66. It would also allow us to get rid of .GetIssueInfos
, which to me seems like a hack.
Would it be possible to hold off adding these links to a separate PR? The links are unrelated to fixing the deleted-comment bug, and it seems to me that the best way to add support for the links requires some more refactoring.
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 think that the best solution is that I leave the links in place (except the link you mentioned). The .GetCommentLink function is also needed for backward-compatibility reasons. So actions that created before the update won't have a comment_id assigned. So .Comment.HTMLURL would not work.
I think that adding these links does not need to be holed off to another PR.
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.
Good point about backwards compatibility, I didn't think of that.
routers/user/home.go
Outdated
@@ -74,6 +74,7 @@ func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isPr | |||
if ctx.User != nil { | |||
userCache[ctx.User.ID] = ctx.User | |||
} | |||
commentCache := map[int64]*models.Comment{} |
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 far as I can tell, there will never be two actions with the same (non-zero) CommentID
, so I don't see any point in caching comments.
routers/user/home.go
Outdated
@@ -115,6 +129,7 @@ func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isPr | |||
return | |||
} | |||
} | |||
|
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.
Please remove this blank line
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.
Why? gofmt did not remove this line.
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.
Nor did gofmt add it 😄. I'm generally opposed to unnecessary whitespace changes, particularly when they are far away from a commit's actual changes; they end up making the git history more complex (i.e. looking at a file's blame).
Added improved links to comments in feed entries. (+ gofmt) Signed-off-by: Jonas Franz <email@jfdev.de>
…f-by: Jonas Franz <email@jfdev.de>
LGTM |
models/action.go
Outdated
} | ||
|
||
return issue.HTMLURL() | ||
|
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.
Please remove unneeded newline after last return and before both if err != nil {
models/issue_comment.go
Outdated
@@ -641,5 +643,12 @@ func DeleteComment(comment *Comment) error { | |||
} | |||
} | |||
|
|||
//Delete associated Action | |||
if _, err := sess.Delete(&Action{ |
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.
Please don't delete actions. Rather check in the dashboard if the comment exists or not and act accordingly.
…nced in actions. Signed-off-by: Jonas Franz <email@jfdev.de>
models/action.go
Outdated
|
||
if !opts.IncludeDeletedComments { | ||
// commentID != 0 AND comment exist | ||
sess.And("(comment_id ISNULL OR comment_id = 0 OR EXISTS(SELECT NULL FROM comment c WHERE comment_id = c.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.
Select is invalid as there is no such ISNULL
. Also selects with OR
are very hard to optimize for dbms so mostly they are slow on large tables and this one is such. I would better prefer if there would be added new bool
field that action has been deleted
that would be updated to true on deleting comment etc
models/action.go
Outdated
issueIDString := a.GetIssueInfos()[0] | ||
issueID, err := strconv.ParseInt(issueIDString, 10, 64) | ||
|
||
if err != nil { |
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.
Please remove newline before if err != nil {
models/action.go
Outdated
|
||
issue, err := GetIssueByID(issueID) | ||
|
||
if err != nil { |
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.
Please remove newline before if err != nil {
Signed-off-by: Jonas Franz <email@jfdev.de>
models/action.go
Outdated
Repo *Repository `xorm:"-"` | ||
CommentID int64 `xorm:"INDEX"` | ||
Comment *Comment `xorm:"-"` | ||
CommentDeleted bool `xorm:"default 0 not null"` |
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.
Do not use 0 and 1 but true and false just like it is used in IsPrivate. Cant this field be reused for other optypes also? So maybe is better call it IsDeleted?
models/issue_comment.go
Outdated
@@ -641,5 +643,7 @@ func DeleteComment(comment *Comment) error { | |||
} | |||
} | |||
|
|||
sess.Exec("UPDATE `action` SET comment_deleted = 1 WHERE comment_id = ?", comment.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.
Use xorm update function
Introducing "IsDeleted" column to action. Signed-off-by: Jonas Franz <email@jfdev.de>
LGTM |
Does migration updates deleted field for already deleted comments? |
@lafriks as discussed in Discord, we have no way of knowing since there was no link between Action and Comment before this PR :( |
@lafriks CommentID will be added by this migration. Before this, theire was no ability to identify the comment except of the column "content" that only contains a small snippet of text from the original comment. So no way to reconstruct the old comment at all. (besides searching based on the given snippet in "content") 😢 |
@JonasFranzDEV @bkcsoft oh right, than it is fine 👍 |
Fixes #1956
Adds a "CommentID" column to the action model (+migration). This is useful for deleting associated actions when a comment should be deleted.
Adds a link to the comment in the associated feed entry.