Skip to content

Fix loading content history on show more #17819

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
merged 10 commits into from
Dec 6, 2021

Conversation

Gusted
Copy link
Contributor

@Gusted Gusted commented Nov 25, 2021

- Call `initRepoIssueContentHistory` so that the newly loaded issues
also get their content history.
- Resolves go-gitea#17767
@silverwind
Copy link
Member

silverwind commented Nov 26, 2021

Kind of unrelated but I don't like it that initRepoIssueContentHistory does an unconditional fetch request. I feel like this is something that could have been rendered directly into the HTML instead.

It might be better to do that fetch only when clicking the edit history, via a delegated event listener on a parent node.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 26, 2021
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 26, 2021

I think we should prevent init something again and again. init usually means a one-time work.

As silverwind suggested, we may try to attach some event listeners to parent DOM node. ps: "something have been rendered directly into the HTML instead" seems more complex than this solution, it would break related code into many functions.

Or, we can use a re-call safe function, eg: attachXxx, like the existing attachTribute, then developers are clear that it can be called on demand. And in the attachXxx, we can only fetch the new content history data we need.

Copy link
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

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

I guess it's a good short-term fix.

@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 26, 2021
@jpraet
Copy link
Member

jpraet commented Nov 26, 2021

Note that the ticket #17767 also mentions the scenario where a diff of a file is initially hidden because it is too large.
When you click "Load Diff", the comment edit history is missing too. I think this PR currently only handles the "Show More" scenario.

@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 27, 2021
@lunny lunny added type/bug skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels Nov 27, 2021
@zeripath
Copy link
Contributor

So we'd need to add:

diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js
index 5f231b6c8..f8f6c38b7 100644
--- a/web_src/js/features/repo-diff.js
+++ b/web_src/js/features/repo-diff.js
@@ -127,6 +127,7 @@ export function initRepoDiffShowMore() {
       }
 
       $target.parent().replaceWith($(resp).find('#diff-file-boxes .diff-file-body .file-body').children());
+      initRepoIssueContentHistory();
     }).fail(() => {
       $target.removeClass('disabled');
     });

if we wanted to catch the show diff too.

I think however, we should consider if we want to load the history like this - would it be better to have it be dynamically loaded when the user requests to see the history?

@Gusted
Copy link
Contributor Author

Gusted commented Nov 28, 2021

I think however, we should consider if we want to load the history like this - would it be better to have it be dynamically loaded when the user requests to see the history?

I think it's best if we add a attribute to a comment if it has history, and the front-end would request the history on demand. Any objections?

@zeripath
Copy link
Contributor

No objections from me. This would simplify a lot of things and reduce the risk of serious problems with heavily edited issues and PRs.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 29, 2021

I think however, we should consider if we want to load the history like this - would it be better to have it be dynamically loaded when the user requests to see the history?

I think it's best if we add a attribute to a comment if it has history, and the front-end would request the history on demand. Any objections?

I think it can be done mostly in frontend, then we do not need to change backend code (no more dependencies or coupling, no need to make template files more complex)

  1. initRepoIssueContentHistory() => attachRepoIssueContentHistory(targetCommentId=null)
  2. GET /content-history/overview => POST /content-history/overview with {commentIdList: [...] }, only query the overview information for commentIdList
  3. If targetCommentId==null, attachRepoIssueContentHistory would collect all history-menu-not-attached comment IDs, and send to backend to query overview.
  4. Then re-calling attachRepoIssueContentHistory(null) won't send redundant requests, we can call it safely at any time (Improvement)
  5. If a content is edited, we can call attachRepoIssueContentHistory(commentId) to do a refresh and show the history menu (Improvement)

@codecov-commenter

This comment has been minimized.

@6543 6543 added this to the 1.16.0 milestone Dec 2, 2021
@Gusted Gusted deleted the fix-contenthistory-show-more branch January 2, 2022 22:49
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
* Fix loading content history on show more

- Call `initRepoIssueContentHistory` so that the newly loaded issues
also get their content history.
- Resolves go-gitea#17767

* apply history to show diff too

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: zeripath <[email protected]>
Co-authored-by: 6543 <[email protected]>
@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/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code comment history not shown on lazily loaded diffs
9 participants