Merge "Preload edit and drafts REST requests"
diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
index 2ebe457..c58f888 100644
--- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
+++ b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
@@ -121,8 +121,9 @@
}
/** Returns dynamic parameters of {@code index.html}. */
- public static Map<String, Map<String, SanitizedContent>> dynamicTemplateData(GerritApi gerritApi)
+ public static Map<String, Object> dynamicTemplateData(GerritApi gerritApi)
throws RestApiException {
+ ImmutableMap.Builder<String, Object> data = ImmutableMap.builder();
Gson gson = OutputFormat.JSON_COMPACT.newGson();
Map<String, SanitizedContent> initialData = new HashMap<>();
Server serverApi = gerritApi.config().server();
@@ -141,14 +142,15 @@
initialData.put(
"\"/accounts/self/preferences.edit\"",
serializeObject(gson, accountApi.getEditPreferences()));
+ data.put("userIsAuthenticated", true);
} catch (AuthException e) {
logger.atFine().withCause(e).log(
"Can't inline account-related data because user is unauthenticated");
// Don't render data
- // TODO(hiesel): Tell the client that the user is not authenticated so that it doesn't have to
- // fetch anyway. This requires more client side modifications.
}
- return ImmutableMap.of("gerritInitialData", initialData);
+
+ data.put("gerritInitialData", initialData);
+ return data.build();
}
/** Returns all static parameters of {@code index.html}. */
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
index 2eb727c..5b88d34 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
@@ -1661,7 +1661,7 @@
endpoint: '/edit/',
params,
reportEndpointAsIs: true,
- });
+ }, true);
});
}
diff --git a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
index 757c167..0bd1780 100644
--- a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
+++ b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
@@ -33,6 +33,7 @@
{@param? defaultDiffDetailHex: ?}
{@param? preloadChangePage: ?}
{@param? preloadDiffPage: ?}
+ {@param? userIsAuthenticated: ?}
<!DOCTYPE html>{\n}
<html lang="en">{\n}
<meta charset="utf-8">{\n}
@@ -84,12 +85,21 @@
{if $changeRequestsPath}
{if $preloadChangePage and $defaultChangeDetailHex}
<link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/detail?O={$defaultChangeDetailHex}" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+ {if $userIsAuthenticated}
+ <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/edit/?download-commands=true" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+ {/if}
{/if}
{if $preloadDiffPage and $defaultDiffDetailHex}
<link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/detail?O={$defaultDiffDetailHex}" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+ {if $userIsAuthenticated}
+ <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/edit/" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+ {/if}
{/if}
<link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/comments" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
<link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/robotcomments" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+ {if $userIsAuthenticated}
+ <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/drafts" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+ {/if}
{/if}
// RobotoMono fonts are used in styles/fonts.css