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

Fix "Dashboard shows deleted comments" #1995

Merged
merged 24 commits into from
Jun 25, 2017
Merged

Conversation

jonasfranz
Copy link
Member

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.

jonasfranz and others added 17 commits May 4, 2017 17:58
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>
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"
Copy link
Member

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

Copy link
Member Author

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>
@@ -0,0 +1,24 @@
// Copyright 2017 The Gogs Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Gitea authors

Copy link
Member Author

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>
@lunny lunny added this to the 1.2.0 milestone Jun 17, 2017
@lunny lunny added the type/bug label Jun 17, 2017
comment, err = models.GetCommentByID(act.CommentID)
if err != nil {
if models.IsErrCommentNotExist(err) {
continue
Copy link
Member

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.

<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>
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@@ -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{}
Copy link
Member

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.

@@ -115,6 +129,7 @@ func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isPr
return
}
}

Copy link
Member

@ethantkoenig ethantkoenig Jun 17, 2017

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

Copy link
Member Author

@jonasfranz jonasfranz Jun 17, 2017

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.

Copy link
Member

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>
@lunny
Copy link
Member

lunny commented Jun 18, 2017

LGTM

@tboerger tboerger added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Jun 18, 2017
models/action.go Outdated
}

return issue.HTMLURL()

Copy link
Member

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 {

@@ -641,5 +643,12 @@ func DeleteComment(comment *Comment) error {
}
}

//Delete associated Action
if _, err := sess.Delete(&Action{
Copy link
Member

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))")
Copy link
Member

@lafriks lafriks Jun 22, 2017

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 {
Copy link
Member

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 {
Copy link
Member

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"`
Copy link
Member

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?

@@ -641,5 +643,7 @@ func DeleteComment(comment *Comment) error {
}
}

sess.Exec("UPDATE `action` SET comment_deleted = 1 WHERE comment_id = ?", comment.ID)
Copy link
Member

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>
@bkcsoft
Copy link
Member

bkcsoft commented Jun 25, 2017

LGTM

@tboerger tboerger 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 Jun 25, 2017
@bkcsoft bkcsoft merged commit 441986a into go-gitea:master Jun 25, 2017
@lafriks
Copy link
Member

lafriks commented Jun 25, 2017

Does migration updates deleted field for already deleted comments?

@bkcsoft
Copy link
Member

bkcsoft commented Jun 25, 2017

@lafriks as discussed in Discord, we have no way of knowing since there was no link between Action and Comment before this PR :(

@jonasfranz
Copy link
Member Author

@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") 😢

@lafriks
Copy link
Member

lafriks commented Jun 25, 2017

@JonasFranzDEV @bkcsoft oh right, than it is fine 👍

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
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. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dashboard shows deleted comments
7 participants