feat(gatsby): Reduce cost of sourcing after the initial (#33692)
feat(gatsby): Reduce cost of sourcing after the initial (#33692)

* feat(gatsby): Reduce cost of sourcing after the initial

We take some expensive steps after sourcing to warn plugin authors about possible errors and to
remove stale nodes from previous cached builds.

But these are no-ops on subsequent sources so we should skip them.

Calling getNodes() is especially expensive with LMDB (roughly 1s / 50k nodes on my machine). Deleting stale nodes is around 1s / 200k nodes. For one large site with ~700k nodes, making this change dropped sourcing time by ~15s.

* Update packages/gatsby/src/utils/source-nodes.ts

Co-authored-by: Ward Peeters <f7d6f8166205aa91930091f422c0634df8a7ceb4@coding-tech.com>

* Update source-nodes.ts

* Update packages/gatsby/src/utils/source-nodes.ts

Co-authored-by: Ward Peeters <f7d6f8166205aa91930091f422c0634df8a7ceb4@coding-tech.com>

* Add back mistakenly deleted line

* chore: format

Co-authored-by: Ward Peeters <f7d6f8166205aa91930091f422c0634df8a7ceb4@coding-tech.com>
Co-authored-by: gatsbybot <313a651c59fdaade90d152972001707d94b0975c@gmail.com>
gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby