summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2010-02-23 20:07:23 -0800
committerShawn O. Pearce <sop@google.com>2010-02-23 20:07:28 -0800
commit0a53362384246c087c815762aead7fd296fbb2b5 (patch)
treee96292fe669fa3edca0eeb470ac00e5174f1fd30
parentf6dd8a9e710c851f756e51038d44eca9164fa4bc (diff)
Don't RPC to load the full file if we already have it
If the user is toggling the "Show full file" flag and we already were given the full file contents just so we can do proper syntax highlighting, don't RPC to load the same script again. Instead just reformat the UI and update it. Because this can take a bit of local CPU time, we don't do it on the event handler but instead display the "Loading" box and run it after the current event finishes. This way the checkbox can update and the user can see that we are working. Change-Id: I70d16803c61f91f7060b7f8c91b766f3437b8d1f Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java7
-rw-r--r--gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java6
-rw-r--r--gerrit-gwtui/src/main/java/com/google/gerrit/client/RpcStatus.java2
-rw-r--r--gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java40
4 files changed, 46 insertions, 9 deletions
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java
index dff0303346..1c92172a7b 100644
--- a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java
+++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchScript.java
@@ -87,8 +87,8 @@ public class PatchScript {
return history;
}
- public int getContext() {
- return settings.getContext();
+ public PatchScriptSettings getSettings() {
+ return settings;
}
public boolean isIgnoreWhitespace() {
@@ -138,6 +138,7 @@ public class PatchScript {
}
public Iterable<EditList.Hunk> getHunks() {
- return new EditList(edits, getContext(), a.size(), b.size()).getHunks();
+ final int ctx = settings.getContext();
+ return new EditList(edits, ctx, a.size(), b.size()).getHunks();
}
}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java
index a4035d5f66..d26d7362c7 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java
@@ -273,9 +273,9 @@ public class Gerrit implements EntryPoint {
};
gBody.add(body);
- final RpcStatus rpcStatus = new RpcStatus(gTopMenu);
- JsonUtil.addRpcStartHandler(rpcStatus);
- JsonUtil.addRpcCompleteHandler(rpcStatus);
+ RpcStatus.INSTANCE = new RpcStatus(gTopMenu);
+ JsonUtil.addRpcStartHandler(RpcStatus.INSTANCE);
+ JsonUtil.addRpcCompleteHandler(RpcStatus.INSTANCE);
JsonUtil.setDefaultXsrfManager(new XsrfManager() {
@Override
public String getToken(JsonDefTarget proxy) {
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/RpcStatus.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/RpcStatus.java
index 6f18da3a2d..21c5154802 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/RpcStatus.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/RpcStatus.java
@@ -24,6 +24,8 @@ import com.google.gwtjsonrpc.client.event.RpcStartEvent;
import com.google.gwtjsonrpc.client.event.RpcStartHandler;
public class RpcStatus implements RpcStartHandler, RpcCompleteHandler {
+ public static RpcStatus INSTANCE;
+
private static int hideDepth;
/** Execute code, hiding the RPCs they execute from being shown visually. */
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java
index 6848249e32..8985f13bfc 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/PatchScreen.java
@@ -19,6 +19,7 @@ import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CO
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
+import com.google.gerrit.client.RpcStatus;
import com.google.gerrit.client.changes.ChangeScreen;
import com.google.gerrit.client.changes.PatchTable;
import com.google.gerrit.client.changes.Util;
@@ -48,6 +49,8 @@ import com.google.gwt.event.logical.shared.OpenHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DisclosurePanel;
@@ -138,6 +141,7 @@ public abstract class PatchScreen extends Screen {
private AbstractPatchContentTable contentTable;
private int rpcSequence;
+ private PatchScript lastScript;
/** The index of the file we are currently looking at among the fileList */
private int patchIndex;
@@ -229,7 +233,8 @@ public abstract class PatchScreen extends Screen {
add(createNextPrevLinks());
contentPanel = new FlowPanel();
- contentPanel.setStyleName(Gerrit.RESOURCES.css().sideBySideScreenSideBySideTable());
+ contentPanel.setStyleName(Gerrit.RESOURCES.css()
+ .sideBySideScreenSideBySideTable());
contentPanel.add(noDifference);
contentPanel.add(contentTable);
add(contentPanel);
@@ -259,7 +264,8 @@ public abstract class PatchScreen extends Screen {
private void initDisplayControls() {
final Grid displayControls = new Grid(0, 5);
- displayControls.setStyleName(Gerrit.RESOURCES.css().patchScreenDisplayControls());
+ displayControls.setStyleName(Gerrit.RESOURCES.css()
+ .patchScreenDisplayControls());
add(displayControls);
createIgnoreWhitespace(displayControls, 0, 0);
@@ -278,15 +284,41 @@ public abstract class PatchScreen extends Screen {
cb.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
+ final PatchScript last = lastScript;
if (event.getValue()) {
- // Show a diff of the full files
scriptSettings.setContext(WHOLE_FILE_CONTEXT);
+ if (last != null && last.getA().isWholeFile()) {
+ final int max = Math.max(last.getA().size(), last.getB().size());
+ last.getSettings().setContext(max);
+ updateNoRpc(last);
+ return;
+ }
} else {
// Restore the context lines to the user's preference
initContextLines();
+ final int n = scriptSettings.getContext();
+ if (last != null && n <= last.getSettings().getContext()) {
+ last.getSettings().setContext(n);
+ updateNoRpc(last);
+ return;
+ }
}
refresh(false /* not the first time */);
}
+
+ private void updateNoRpc(final PatchScript last) {
+ RpcStatus.INSTANCE.onRpcStart(null);
+ DeferredCommand.addCommand(new Command() {
+ @Override
+ public void execute() {
+ try {
+ onResult(last, false /* not the first time */);
+ } finally {
+ RpcStatus.INSTANCE.onRpcComplete(null);
+ }
+ }
+ });
+ }
});
parent.setWidget(row, col + 1, cb);
@@ -403,6 +435,7 @@ public abstract class PatchScreen extends Screen {
protected void refresh(final boolean isFirst) {
final int rpcseq = ++rpcSequence;
+ lastScript = null;
PatchUtil.DETAIL_SVC.patchScript(patchKey, idSideA, idSideB,
scriptSettings, new ScreenLoadCallback<PatchScript>(this) {
@Override
@@ -462,6 +495,7 @@ public abstract class PatchScreen extends Screen {
contentTable.finishDisplay();
}
showPatch(hasDifferences);
+ lastScript = script;
// Mark this file reviewed as soon we display the diff screen
if (Gerrit.isSignedIn() && isFirst) {