Simplify patch display to a single RPC
A long time ago I thought it might make sense to make the RPCs for patch display two parts. The first part was a static patchScript that only returns the file content, and thus could be infinitely cacheable on edge proxies because the content never changes. The second part was supposed to be a dynamic comment list, showing the current comments in the file. This didn't really work out. The static patchScript code actually had to know what comments existed at display time, in order to ensure sufficient context lines were packaged for the client. I also never got around to teaching gwtjsonrpc how to perform cached GET requests. Even if we did, access control rules within a project could change the READ permission from being public readable to being private, which would mean edge proxies might still had that private data. As it turns out, we can simplify the entire code base by putting the two together as a single RPC. We no longer need to perform an RPC join in order to display the result in PatchScreen, and we can cut in half the number of database queries required, as we used to be doing the comment loading work twice per screen display. Change-Id: Ic1a129ff507da0bbe97ca03ce31c566981ed3855 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.reviewdb.Patch;
|
||||
import com.google.gerrit.reviewdb.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.PatchSet;
|
||||
|
||||
@@ -25,9 +24,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommentDetail {
|
||||
protected List<PatchLineComment> commentsA;
|
||||
protected List<PatchLineComment> commentsB;
|
||||
protected List<Patch> history;
|
||||
protected List<PatchLineComment> a;
|
||||
protected List<PatchLineComment> b;
|
||||
protected AccountInfoCache accounts;
|
||||
|
||||
private transient PatchSet.Id idA;
|
||||
@@ -35,12 +33,11 @@ public class CommentDetail {
|
||||
private transient Map<Integer, List<PatchLineComment>> forA;
|
||||
private transient Map<Integer, List<PatchLineComment>> forB;
|
||||
|
||||
public CommentDetail(final PatchSet.Id a, final PatchSet.Id b) {
|
||||
commentsA = new ArrayList<PatchLineComment>();
|
||||
commentsB = new ArrayList<PatchLineComment>();
|
||||
|
||||
idA = a;
|
||||
idB = b;
|
||||
public CommentDetail(final PatchSet.Id idA, final PatchSet.Id idB) {
|
||||
this.a = new ArrayList<PatchLineComment>();
|
||||
this.b = new ArrayList<PatchLineComment>();
|
||||
this.idA = idA;
|
||||
this.idB = idB;
|
||||
}
|
||||
|
||||
protected CommentDetail() {
|
||||
@@ -51,19 +48,19 @@ public class CommentDetail {
|
||||
switch (p.getSide()) {
|
||||
case 0:
|
||||
if (idA == null && idB.equals(psId)) {
|
||||
commentsA.add(p);
|
||||
a.add(p);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (idA != null && idA.equals(psId)) {
|
||||
commentsA.add(p);
|
||||
a.add(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (idB.equals(psId)) {
|
||||
commentsB.add(p);
|
||||
b.add(p);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -75,28 +72,20 @@ public class CommentDetail {
|
||||
accounts = a;
|
||||
}
|
||||
|
||||
public void setHistory(final List<Patch> h) {
|
||||
history = h;
|
||||
}
|
||||
|
||||
public AccountInfoCache getAccounts() {
|
||||
return accounts;
|
||||
}
|
||||
|
||||
public List<Patch> getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
public List<PatchLineComment> getCommentsA() {
|
||||
return commentsA;
|
||||
return a;
|
||||
}
|
||||
|
||||
public List<PatchLineComment> getCommentsB() {
|
||||
return commentsB;
|
||||
return b;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return commentsA.isEmpty() && commentsB.isEmpty();
|
||||
return a.isEmpty() && b.isEmpty();
|
||||
}
|
||||
|
||||
public List<PatchLineComment> getForA(final int lineNbr) {
|
||||
@@ -104,7 +93,7 @@ public class CommentDetail {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (forA == null) {
|
||||
forA = index(commentsA);
|
||||
forA = index(a);
|
||||
}
|
||||
return get(forA, lineNbr);
|
||||
}
|
||||
@@ -114,7 +103,7 @@ public class CommentDetail {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (forB == null) {
|
||||
forB = index(commentsB);
|
||||
forB = index(b);
|
||||
}
|
||||
return get(forB, lineNbr);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,6 @@ public interface PatchDetailService extends RemoteJsonService {
|
||||
void patchScript(Patch.Key key, PatchSet.Id a, PatchSet.Id b,
|
||||
PatchScriptSettings settings, AsyncCallback<PatchScript> callback);
|
||||
|
||||
void patchComments(Patch.Key key, PatchSet.Id a, PatchSet.Id b,
|
||||
AsyncCallback<CommentDetail> callback);
|
||||
|
||||
@SignInRequired
|
||||
void saveDraft(PatchLineComment comment,
|
||||
AsyncCallback<PatchLineComment> callback);
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.gerrit.prettify.common.PrettySettings;
|
||||
import com.google.gerrit.prettify.common.SparseFileContent;
|
||||
import com.google.gerrit.prettify.common.SparseHtmlFile;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.Patch;
|
||||
|
||||
import org.eclipse.jgit.diff.Edit;
|
||||
|
||||
@@ -40,11 +41,13 @@ public class PatchScript {
|
||||
protected List<Edit> edits;
|
||||
protected DisplayMethod displayMethodA;
|
||||
protected DisplayMethod displayMethodB;
|
||||
protected CommentDetail comments;
|
||||
protected List<Patch> history;
|
||||
|
||||
public PatchScript(final Change.Key ck, final List<String> h,
|
||||
final PatchScriptSettings s, final SparseFileContent ca,
|
||||
final SparseFileContent cb, final List<Edit> e, final DisplayMethod ma,
|
||||
final DisplayMethod mb) {
|
||||
final DisplayMethod mb, final CommentDetail cd, final List<Patch> hist) {
|
||||
changeId = ck;
|
||||
header = h;
|
||||
settings = s;
|
||||
@@ -53,6 +56,8 @@ public class PatchScript {
|
||||
edits = e;
|
||||
displayMethodA = ma;
|
||||
displayMethodB = mb;
|
||||
comments = cd;
|
||||
history = hist;
|
||||
}
|
||||
|
||||
protected PatchScript() {
|
||||
@@ -74,6 +79,14 @@ public class PatchScript {
|
||||
return header;
|
||||
}
|
||||
|
||||
public CommentDetail getCommentDetail() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public List<Patch> getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
public int getContext() {
|
||||
return settings.getContext();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user