message: gitrest: pre-compute latest summary for Historian caching
diff: @@ -24,6 +24,7 @@ import {
  } from "@fluidframework/server-services-client";
  import { Router } from "express";
  import { Provider } from "nconf";
  +import winston from "winston";
  import { getExternalWriterParams, IRepositoryManager, IRepositoryManagerFactory } from "../utils";
  import { handleResponse } from "./utils";
  @@ -220,7 +221,6 @@ export class WholeSummaryWriteGitManager {
  { enabled: this.externalStorageEnabled },
  );
  }
  - // TODO: precompute latest summary and return, or cache locally
  return {
  id: commit.sha,
  };
  @@ -383,7 +383,7 @@ export function create(
  */
  router.post("/repos/:owner/:repo/git/summaries", async (request, response) => {
  const storageRoutingId: string = request.get("Storage-Routing-Id");
  - const [,documentId] = storageRoutingId.split(":");
  + const [tenantId,documentId] = storageRoutingId.split(":");
  if (!documentId) {
  handleResponse(Promise.reject(new NetworkError(400, "Invalid Storage-Routing-Id header")), response);
  return;
  @@ -392,12 +392,34 @@ export function create(
  const resultP = repoManagerFactory.open(
  request.params.owner,
  request.params.repo,
  - ).then(async (repoManager) => createSummary(
  + ).then(async (repoManager): Promise<IWriteSummaryResponse | IWholeFlatSummary> => {
  + const externalStorageEnabled =
  + getExternalWriterParams(request.query?.config as string | undefined)?.enabled ?? false;
  + const writeSummaryResponse = await createSummary(
  repoManager,
  wholeSummaryPayload,
  documentId,
  - getExternalWriterParams(request.query?.config as string | undefined)?.enabled ?? false,
  - ));
  + externalStorageEnabled,
  + );
  + if (wholeSummaryPayload.type === "container") {
  + try {
  + const wholeFlatSummary = await getSummary(
  + repoManager,
  + writeSummaryResponse.id,
  + documentId,
  + externalStorageEnabled,
  + );
  + return wholeFlatSummary;
  + } catch (e) {
  + // This read is for Historian caching purposes, so it should be ignored on failure.
  + winston.error("Failed to read latest summary after writing container summary", {
  + documentId,
  + tenantId,
  + });
  + }
  + }
  + return writeSummaryResponse;
  + });
  handleResponse(resultP, response, 201);
  });
  