Aggressively cache Screen widgets to accelerate forward/back

When browsing changes it is very common for a user to be on their own
dashboard, click on a change, jump back, then jump to another change.
We want to make the "jump back" part really fast.  Its unlikely that
the data in the dashboard has really changed since the last time the
user looked at it, so recycling the entire widget graph saves us time
in constructing the DOM elements over again for the table.  If rows
did get removed or were inserted the table will update itself once the
RPC call is complete.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-12-03 12:48:55 -08:00
parent 870c428ebb
commit 156a224fcd
8 changed files with 112 additions and 33 deletions

View File

@@ -14,12 +14,12 @@
package com.google.gerrit.client.changes;
import com.google.gerrit.client.Link;
import com.google.gerrit.client.data.AccountDashboardInfo;
import com.google.gerrit.client.data.AccountInfo;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.Screen;
import com.google.gwt.user.client.History;
public class AccountDashboardScreen extends Screen {
@@ -29,44 +29,49 @@ public class AccountDashboardScreen extends Screen {
private ChangeTable.Section forReview;
private ChangeTable.Section closed;
public AccountDashboardScreen() {
this(null);
public AccountDashboardScreen(final Account.Id id) {
ownerId = id;
}
public AccountDashboardScreen(final Account.Id id) {
super("");
@Override
public Object getScreenCacheToken() {
return getClass();
}
ownerId = id;
table = new ChangeTable();
byOwner = new ChangeTable.Section("");
forReview = new ChangeTable.Section("");
closed = new ChangeTable.Section("");
table.addSection(byOwner);
table.addSection(forReview);
table.addSection(closed);
add(table);
if (ownerId == null) {
setRequiresSignIn(true);
}
@Override
public Screen recycleThis(final Screen newScreen) {
ownerId = ((AccountDashboardScreen) newScreen).ownerId;
return this;
}
@Override
public void onLoad() {
if (table == null) {
table = new ChangeTable();
byOwner = new ChangeTable.Section("");
forReview = new ChangeTable.Section("");
closed = new ChangeTable.Section("");
table.addSection(byOwner);
table.addSection(forReview);
table.addSection(closed);
add(table);
}
table.setSavePointerId(Link.toAccountDashboard(ownerId));
super.onLoad();
table.setSavePointerId(History.getToken());
Util.LIST_SVC.forAccount(ownerId,
new GerritCallback<AccountDashboardInfo>() {
public void onSuccess(final AccountDashboardInfo r) {
display(r);
// TODO Actually we want to cancel the RPC if detached.
if (isAttached()) {
display(r);
}
}
});
}
private void display(final AccountDashboardInfo r) {
final AccountInfo o = r.getOwner();
setTitleText(Util.M.accountDashboardTitle(o.getFullName()));
byOwner.setTitleText(Util.M.changesUploadedBy(o.getFullName()));
forReview.setTitleText(Util.M.changesReviewableBy(o.getFullName()));

View File

@@ -15,15 +15,34 @@
package com.google.gerrit.client.changes;
import com.google.gerrit.client.data.ChangeInfo;
import com.google.gerrit.client.reviewdb.Change;
import com.google.gerrit.client.ui.Screen;
public class ChangeScreen extends Screen {
public ChangeScreen(final int id) {
super("Loading Change " + id);
private Change.Id changeId;
public ChangeScreen(final Change.Id toShow) {
changeId = toShow;
}
public ChangeScreen(final ChangeInfo c) {
super(c.getSubject());
this(c.getId());
}
@Override
public Object getScreenCacheToken() {
return getClass();
}
@Override
public Screen recycleThis(final Screen newScreen) {
changeId = ((ChangeScreen) newScreen).changeId;
return this;
}
@Override
public void onLoad() {
setTitleText("Change " + changeId.get());
}
}

View File

@@ -19,7 +19,6 @@ import com.google.gerrit.client.Link;
import com.google.gerrit.client.SignedInListener;
import com.google.gerrit.client.data.ChangeInfo;
import com.google.gerrit.client.reviewdb.Change;
import com.google.gerrit.client.reviewdb.Change.Id;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
@@ -73,7 +72,7 @@ public class ChangeTable extends Composite implements HasFocus {
private static final LinkedHashMap<String, Change.Id> savedPositions =
new LinkedHashMap<String, Change.Id>(10, 0.75f, true) {
@Override
protected boolean removeEldestEntry(Entry<String, Id> eldest) {
protected boolean removeEldestEntry(Entry<String, Change.Id> eldest) {
return size() >= 5;
}
};

View File

@@ -14,10 +14,10 @@
package com.google.gerrit.client.changes;
import com.google.gerrit.client.Link;
import com.google.gerrit.client.data.ChangeInfo;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.AccountScreen;
import com.google.gwt.user.client.History;
import java.util.List;
@@ -33,13 +33,19 @@ public class MineStarredScreen extends AccountScreen {
starred = new ChangeTable.Section();
table.addSection(starred);
table.setSavePointerId(Link.MINE_STARRED);
add(table);
}
@Override
public Object getScreenCacheToken() {
return Link.MINE_STARRED;
}
@Override
public void onLoad() {
super.onLoad();
table.setSavePointerId(History.getToken());
Util.LIST_SVC.myStarredChanges(new GerritCallback<List<ChangeInfo>>() {
public void onSuccess(final List<ChangeInfo> result) {
starred.display(result);