Skip to content

Commit

Permalink
perf(gatsby-plugin-page-creator): use set for tracking existing files (
Browse files Browse the repository at this point in the history
…#27336)

* perf(gatsby-plugin-page-creator): use set for tracking existing files

* Also drop the now unused lodash dep
  • Loading branch information
pvdz committed Oct 8, 2020
1 parent 18eee9d commit 843259e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/gatsby-plugin-page-creator/src/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import glob from "globby"
import _ from "lodash"
import systemPath from "path"
import { sync as existsSync } from "fs-exists-cached"
import {
Expand Down Expand Up @@ -67,17 +66,19 @@ Please pick a path to an existing directory.`)
const pagesGlob = `**/*.{${exts}}`

// Get initial list of files.
let files = await glob(pagesGlob, { cwd: pagesPath })
const files = await glob(pagesGlob, { cwd: pagesPath })
files.forEach(file => {
createPage(file, pagesDirectory, actions, ignore, graphql, reporter)
})

const knownFiles = new Set(files)

watchDirectory(
pagesPath,
pagesGlob,
addedPath => {
try {
if (!_.includes(files, addedPath)) {
if (!knownFiles.has(addedPath)) {
createPage(
addedPath,
pagesDirectory,
Expand All @@ -86,7 +87,7 @@ Please pick a path to an existing directory.`)
graphql,
reporter
)
files.push(addedPath)
knownFiles.add(addedPath)
}
} catch (e) {
reporter.panic(
Expand All @@ -108,7 +109,7 @@ Please pick a path to an existing directory.`)
})
}
})
files = files.filter(f => f !== removedPath)
knownFiles.delete(removedPath)
} catch (e) {
reporter.panic(
e.message.startsWith(`PageCreator`)
Expand Down

0 comments on commit 843259e

Please sign in to comment.