Skip to content

Commit

Permalink
Show notice inviting users to use query on demand if their page query…
Browse files Browse the repository at this point in the history
… running takes more than 2 minutes
  • Loading branch information
pieh committed Nov 18, 2020
1 parent 3b97e81 commit 0316827
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/gatsby/src/services/run-page-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { processPageQueries } from "../query"
import reporter from "gatsby-cli/lib/reporter"
import { IQueryRunningContext } from "../state-machines/query-running/types"
import { assertStore } from "../utils/assert-store"
import {
showExperimentNoticeAfterTimeout,
CancelExperimentNoticeCallbackOrUndefined,
} from "../utils/show-experiment-notice"
import { isCI } from "gatsby-core-utils"

const TWO_MINUTES = 2 * 60 * 1000

export async function runPageQueries({
parentSpan,
Expand Down Expand Up @@ -35,12 +42,38 @@ export async function runPageQueries({
)

activity.start()

let cancelNotice: CancelExperimentNoticeCallbackOrUndefined
if (
process.env.gatsby_executing_command === `develop` &&
!process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND &&
!isCI()
) {
cancelNotice = showExperimentNoticeAfterTimeout(
`queryOnDemand`,
reporter.stripIndent(`
We noticed that it takes more than two minutes to run your page queries.
Consider using experimental Query on Demand feature which would run queries
when resources for page are requested by browser instead of pre-running
all page queries eagerly.
See https://gatsby.dev/query-on-demand for details.
`),
TWO_MINUTES
)
}

await processPageQueries(pageQueryIds, {
state,
activity,
graphqlRunner,
graphqlTracing: program?.graphqlTracing,
})

if (cancelNotice) {
cancelNotice()
}

activity.done()
}

0 comments on commit 0316827

Please sign in to comment.