Skip to content

Conversation

jpraet
Copy link
Member

@jpraet jpraet commented Nov 21, 2021

* initialize content history when making an edit to an old item created before the introduction of content history
* show edit history for code comments on pull request files tab
@jpraet
Copy link
Member Author

jpraet commented Nov 21, 2021

Should I remove these calls that eagerly initialize the content history when creating a new issue / pr / comment?
Now that the content history is initialized whenever an edit is made this is technically no longer needed.

gitea/models/issue.go

Lines 1015 to 1018 in d710af6

if err = issues.SaveIssueContentHistory(e, doer.ID, opts.Issue.ID, 0,
timeutil.TimeStampNow(), opts.Issue.Content, true); err != nil {
return err
}

err = issues.SaveIssueContentHistory(db.GetEngine(db.DefaultContext), doer.ID, issue.ID, comment.ID, timeutil.TimeStampNow(), comment.Content, true)
if err != nil {
return nil, err
}

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 21, 2021
// UpdateComment updates information of comment.
func UpdateComment(c *models.Comment, doer *models.User, oldContent string) error {
var needsContentHistory = c.Content != oldContent &&
(c.Type == models.CommentTypeComment || c.Type == models.CommentTypeReview || c.Type == models.CommentTypeCode)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we have content history for "pending" code comments on non-submitted review? GitHub doesn't do that either.

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't thought about it. For a simple idea, if the logic is not complex then we can have it, but if we need to pay much effect to follow the GitHub behavior, well, it depends 😂. Both are fine to me.

jpraet and others added 2 commits November 21, 2021 19:01
Fix a flaw in keepLimitedContentHistory, the first and the last should never be deleted
@wxiaoguang
Copy link
Contributor

I also added a patch to fix a flaw (I was going to fix it, but since we have this PR, so I think it's good to have it now 😊)

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 21, 2021

Should I remove these calls that eagerly initialize the content history when creating a new issue / pr / comment? Now that the content history is initialized whenever an edit is made this is technically no longer needed.

Yep, I think we can remove them, then an issue without editing won't have history data, it would save some storage space.

@wxiaoguang
Copy link
Contributor

Tested on my side and LGTM.

@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 Nov 21, 2021
@wxiaoguang wxiaoguang added this to the 1.16.0 milestone Nov 21, 2021
@wxiaoguang wxiaoguang added the type/enhancement An improvement of existing functionality label Nov 21, 2021
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@8511eec). Click here to learn what that means.
The diff coverage is 56.66%.

❗ Current head b25731e differs from pull request most recent head 547cee9. Consider uploading reports for the commit 547cee9 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17746   +/-   ##
=======================================
  Coverage        ?   45.54%           
=======================================
  Files           ?      807           
  Lines           ?    89885           
  Branches        ?        0           
=======================================
  Hits            ?    40936           
  Misses          ?    42400           
  Partials        ?     6549           
Impacted Files Coverage Δ
models/issue.go 58.65% <25.00%> (ø)
services/comments/comments.go 62.79% <63.63%> (ø)
models/issues/content_history.go 68.99% <72.72%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8511eec...547cee9. Read the comment docs.

@lunny lunny added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Nov 22, 2021
CommentID: commentID,
})
if err != nil {
log.Error("can not fetch issue content history. err=%v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Why not just return the error but add a special log here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it just follows my first PR, a personal preference for error handling.

Usually I would like to report important errors as early as possible.

Otherwise:

  1. The error may be ignored be callers
  2. The caller prints the error with a unrelated stacktrace (especially in Go, the errors don't have stacktrace)

@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 Nov 22, 2021
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
* Improvements to content history

* initialize content history when making an edit to an old item created before the introduction of content history
* show edit history for code comments on pull request files tab

* Fix a flaw in keepLimitedContentHistory
Fix a flaw in keepLimitedContentHistory, the first and the last should never be deleted

* Remove obsolete eager initialization of content history
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
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. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants