From 843259e3ef06c1444f9f88919a3625800004f5e0 Mon Sep 17 00:00:00 2001 From: Peter van der Zee <209817+pvdz@users.noreply.github.com> Date: Thu, 8 Oct 2020 13:34:44 +0200 Subject: [PATCH] perf(gatsby-plugin-page-creator): use set for tracking existing files (#27336) * perf(gatsby-plugin-page-creator): use set for tracking existing files * Also drop the now unused lodash dep --- .../gatsby-plugin-page-creator/src/gatsby-node.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-plugin-page-creator/src/gatsby-node.ts b/packages/gatsby-plugin-page-creator/src/gatsby-node.ts index d82bfa1f2460f..e4fb02b3db9ea 100644 --- a/packages/gatsby-plugin-page-creator/src/gatsby-node.ts +++ b/packages/gatsby-plugin-page-creator/src/gatsby-node.ts @@ -1,5 +1,4 @@ import glob from "globby" -import _ from "lodash" import systemPath from "path" import { sync as existsSync } from "fs-exists-cached" import { @@ -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, @@ -86,7 +87,7 @@ Please pick a path to an existing directory.`) graphql, reporter ) - files.push(addedPath) + knownFiles.add(addedPath) } } catch (e) { reporter.panic( @@ -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`)