Fetch edit preferences when Gerrit client is loaded

Fetching the edit preferences when the Gerrit client is loaded has the
advantage that code that needs the edit preferences doesn't need to
care about lazily fetching the edit preferences when they are not
there yet. It adds one more request to the initial page load, but
during the initial page load we also load the other preferences
(account preferences and diff preferences).

Change-Id: Ied376d0c96795bd4ccc421e7f674fdf4e1d01c66
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-10-13 11:16:26 +02:00
parent 7b6af4ff35
commit 8a389c3830
2 changed files with 16 additions and 22 deletions

View File

@@ -20,6 +20,7 @@ import static com.google.gerrit.common.data.GlobalCapability.VIEW_PLUGINS;
import com.google.gerrit.client.account.AccountApi;
import com.google.gerrit.client.account.AccountCapabilities;
import com.google.gerrit.client.account.EditPreferences;
import com.google.gerrit.client.admin.ProjectScreen;
import com.google.gerrit.client.api.ApiGlue;
import com.google.gerrit.client.api.PluginLoader;
@@ -329,6 +330,7 @@ public class Gerrit implements EntryPoint {
myAccountDiffPref = accountDiffPref;
}
/** @return the edit preferences of the current user, null if not signed-in */
public static EditPreferencesInfo getEditPreferences() {
return editPrefs;
}
@@ -400,6 +402,7 @@ public class Gerrit implements EntryPoint {
static void deleteSessionCookie() {
myAccount = AccountInfo.create(0, null, null, null);
myAccountDiffPref = null;
editPrefs = null;
myPrefs = AccountPreferencesInfo.createDefault();
urlAliasMatcher.clearUserAliases();
xGerritAuth = null;
@@ -488,16 +491,26 @@ public class Gerrit implements EntryPoint {
}
}));
AccountApi.self().view("preferences")
.get(cbg.addFinal(new GerritCallback<AccountPreferencesInfo>() {
.get(cbg.add(new GerritCallback<AccountPreferencesInfo>() {
@Override
public void onSuccess(AccountPreferencesInfo prefs) {
myPrefs = prefs;
onModuleLoad2(result);
}
}));
AccountApi.getEditPreferences(
cbg.addFinal(new GerritCallback<EditPreferences>() {
@Override
public void onSuccess(EditPreferences prefs) {
EditPreferencesInfo prefsInfo = new EditPreferencesInfo();
prefs.copyTo(prefsInfo);
editPrefs = prefsInfo;
}
}));
} else {
myAccount = AccountInfo.create(0, null, null, null);
myPrefs = AccountPreferencesInfo.createDefault();
editPrefs = null;
onModuleLoad2(result);
}
}

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.JumpKeys;
import com.google.gerrit.client.VoidResult;
import com.google.gerrit.client.account.AccountApi;
import com.google.gerrit.client.account.EditPreferences;
import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.changes.ChangeEditApi;
@@ -43,7 +42,6 @@ import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.extensions.client.EditPreferencesInfo;
import com.google.gerrit.extensions.client.KeyMapType;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -117,6 +115,7 @@ public class EditScreen extends Screen {
this.revision = patch.getParentKey();
this.path = patch.get();
this.startLine = startLine - 1;
setRequiresSignIn(true);
add(uiBinder.createAndBindUi(this));
addDomHandler(GlobalKey.STOP_PROPAGATION, KeyPressEvent.getType());
}
@@ -132,26 +131,8 @@ public class EditScreen extends Screen {
protected void onLoad() {
super.onLoad();
EditPreferencesInfo current = Gerrit.getEditPreferences();
if (current == null) {
AccountApi.getEditPreferences(
new GerritCallback<EditPreferences>() {
@Override
public void onSuccess(EditPreferences r) {
prefs = r;
EditPreferencesInfo global = new EditPreferencesInfo();
r.copyTo(global);
Gerrit.setEditPreferences(global);
onLoad2();
}
});
} else {
prefs = EditPreferences.create(current);
onLoad2();
}
}
prefs = EditPreferences.create(Gerrit.getEditPreferences());
private void onLoad2() {
CallbackGroup group1 = new CallbackGroup();
final CallbackGroup group2 = new CallbackGroup();
final CallbackGroup group3 = new CallbackGroup();