Repository: gatsbyjs/gatsby
File: packages/gatsby/src/commands/build.ts (TypeScript)

Code before:
import path from "path"
import report from "gatsby-cli/lib/reporter"
import signalExit from "signal-exit"
import fs from "fs-extra"
import telemetry from "gatsby-telemetry"

import { buildHTML } from "./build-html"
import { buildProductionBundle } from "./build-javascript"
import bootstrap from "../bootstrap"
import apiRunnerNode from "../utils/api-runner-node"
import { GraphQLRunner } from "../query/graphql-runner"
import { copyStaticDirs } from "../utils/get-static-dir"
import { initTracer, stopTracer } from "../utils/tracer"
import db from "../db"
import { store, readState } from "../redux"
import * as appDataUtil from "../utils/app-data"
import { flush } from "../utils/page-data"
import * as WorkerPool from "../utils/worker/pool"
import { structureWebpackErrors } from "../utils/webpack-error-utils"
import {
  userPassesFeedbackRequestHeuristic,
  showFeedbackRequest,
} from "../utils/feedback"
import * as buildUtils from "./build-utils"
import { boundActionCreators } from "../redux/actions"
import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete"
import { IProgram, Stage } from "./types"
import { PackageJson } from "../.."
import {
  calculateDirtyQueries,
  runStaticQueries,
  runPageQueries,
} from "../services"
import * as webpackStatusUtil from "../utils/webpack-status"

let cachedPageData
let cachedWebpackCompilationHash
if (process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES) {
  const { pageData, webpackCompilationHash } = readState()
  // extract only data that we need to reuse and let v8 garbage collect rest of state
  cachedPageData = pageData
  cachedWebpackCompilationHash = webpackCompilationHash

Review comment (suggestion):
could we name this better. All of the other function names were updated to things like `writePageData`. `flush` is super generic and not clear

Code after:
import path from "path"
import report from "gatsby-cli/lib/reporter"
import signalExit from "signal-exit"
import fs from "fs-extra"
import telemetry from "gatsby-telemetry"

import { buildHTML } from "./build-html"
import { buildProductionBundle } from "./build-javascript"
import bootstrap from "../bootstrap"
import apiRunnerNode from "../utils/api-runner-node"
import { GraphQLRunner } from "../query/graphql-runner"
import { copyStaticDirs } from "../utils/get-static-dir"
import { initTracer, stopTracer } from "../utils/tracer"
import db from "../db"
import { store, readState } from "../redux"
import * as appDataUtil from "../utils/app-data"
import { flush as flushPendingPageDataWrites } from "../utils/page-data"
import * as WorkerPool from "../utils/worker/pool"
import { structureWebpackErrors } from "../utils/webpack-error-utils"
import {
  userPassesFeedbackRequestHeuristic,
  showFeedbackRequest,
} from "../utils/feedback"
import * as buildUtils from "./build-utils"
import { boundActionCreators } from "../redux/actions"
import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete"
import { IProgram, Stage } from "./types"
import { PackageJson } from "../.."
import {
  calculateDirtyQueries,
  runStaticQueries,
  runPageQueries,
} from "../services"
import {
  markWebpackStatusAsPending,
  markWebpackStatusAsDone,
} from "../utils/webpack-status"

let cachedPageData
let cachedWebpackCompilationHash
if (process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES) {
  const { pageData, webpackCompilationHash } = readState()