Update and improve the comments hint computation for the diff viewer.
Review Request #13667 — Created March 25, 2024 and submitted
This change makes major updates to the comments hint structure that gets
included in the diff viewer page data. The major driver for this is that
the old implementation did not include correct information about
comments that were made against commit ranges. It was also doing a bunch
of extra queries, using the database to generate the comments
information when we already had most of what we needed fetched.This new implementation simplifies things a little bit by compting more
information at theReviewsDiffViewerView
level, passing it down to the
DiffViewerView
, instead of letting the superclass do things and then
pull the data back out of the context structure.This makes a couple other small improvements:
- The social page info definitions have been consolidated into the base
ReviewRequestContext, and arguments added to
make_review_request_context
to set them there. - The way that diff commits and other objects are queried has been
simplified so we don't fetch things more than once.
This does not yet add UI for commit-specific comments.
- Ran unit tests.
- Tested all the different diff viewer views, including single diffs,
interdiffs, and commit diffs. - Tested that the commit list and commit history diffs worked correctly.
- Tested that the comments hint (in a future change) correctly listed
all diffs, interdiffs, and commit range comments included in the
pending review.
Summary | ID |
---|---|
f0ef9f21fc06d3d2daa32bfae039c5539abd6c47 |
Description | From | Last Updated |
---|---|---|
undefined name 'diff_commits' Column: 49 Error code: F821 |
reviewbot | |
undefined name 'interdiff_commits' Column: 49 Error code: F821 |
reviewbot | |
'reviewboard.diffviewer.models.diffcommit.SerializedDiffCommit' imported but unused Column: 5 Error code: F401 |
reviewbot | |
redefinition of unused '_get_comments_hint' from line 525 Column: 5 Error code: F811 |
reviewbot | |
We're sort of undoing an important optimization here, going from one query for commits spanning diffsets to now 3 queries. … |
chipx86 | |
social-page_title -> social_page_title |
chipx86 | |
With the above fix, I'd expect all of these to go back to their original values. |
chipx86 | |
Summary must be one line. |
chipx86 | |
Can we pass these in as keyword-only args? |
chipx86 | |
Can we sort keys? |
chipx86 | |
To check: Are we pre-fetching associated reviews before this happens? |
chipx86 | |
Since we only use this when we append, we could just use this inline below. Makes it a bit more … |
chipx86 | |
Can we sort keys? |
chipx86 | |
We don't normally use the outer parens for the tuple in this case. |
chipx86 | |
Can we sort the keys? |
chipx86 | |
Same comment about parens. |
chipx86 | |
Blank line here. |
chipx86 | |
Probably no need for a blank line here. |
chipx86 | |
This can just be `bool(self.interdiffset and draft_diffset == self.interdiffset) |
maubin | |
We access draft.diffset a lot here, you could pull that out into a variable, and have it be None if … |
maubin | |
This can just be if draft_diffset: |
maubin | |
Missing a "Version Added" |
maubin |
- Change Summary:
-
- Get all commits when we get the filediffs.
- Properly change DiffViewerView.get_context to be keyword-only.
- Include the new comments hint computation.
- Testing Done:
-
- Ran unit tests.
- Tested all the different diff viewer views, including single diffs,
interdiffs, and commit diffs.
- Tested that the commit list and commit history diffs worked correctly.
+ - Tested that the comments hint (in a future change) correctly listed
all diffs, interdiffs, and commit range comments included in the
pending review.
- Commits:
-
Summary ID ebed0eaa70128e03697028bbf80f2ff63383bc18 0b6025eaf431c465d976eea4c44c88751be7c207 - Diff:
-
Revision 2 (+1386 -404)
Checks run (1 failed, 1 succeeded)
flake8
- Change Summary:
-
Fix a merge-o
- Commits:
-
Summary ID 0b6025eaf431c465d976eea4c44c88751be7c207 c226b91431518075dcc07b7b2e29917f7ff1d285 - Diff:
-
Revision 3 (+958 -406)
Checks run (2 succeeded)
-
-
We're sort of undoing an important optimization here, going from one query for commits spanning diffsets to now 3 queries.
Right off the bat, one of those can be eliminated (we do
interdiffset.commits.all()
twice).Both can be consolidated by looking up
DiffCommit
entries spanning either diffset ID, and then grouping together in a post-process. This is what we had up above, and it brings us back down to 1.Relevant logic from before:
diffset_pks = [diffset.pk] if interdiffset: diffset_pks.append(interdiffset.pk) commits = DiffCommit.objects.filter(diffset_id__in=diffset_pks) for commit in commits: commits_by_diffset_id.setdefault(commit.diffset_id, []).append( commit)
-
-
-
-
-
-
Since we only use this when we append, we could just use this inline below. Makes it a bit more readable.
-
-
-
-
-
-
- Commits:
-
Summary ID c226b91431518075dcc07b7b2e29917f7ff1d285 7ae9fd2ab375579b2da8a879c0492bcbdd5ca88e
Checks run (2 succeeded)
- Commits:
-
Summary ID 7ae9fd2ab375579b2da8a879c0492bcbdd5ca88e 9129080f53b94d141dadcd352b26efdf675d894f